asp.net – 按钮单击在更新面板中不起作用

前端之家收集整理的这篇文章主要介绍了asp.net – 按钮单击在更新面板中不起作用前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
当我在Update面板中使用Button时,它不会触发click事件,但在更新面板之外它可以工作.

这是代码

<asp:UpdatePanel ID="updatePanel2" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="false">
    <ContentTemplate>
    <asp:Button ID="btnBlock" class="Button" Text="BlockCalls" runat="server"       
            onclick="btnBlock_Click" Enabled="True" Width="100px" />  
    </ContentTemplate>
    <Triggers>
        <asp:AsyncPostBackTrigger ControlID="btnBlock" /> 
    </Triggers>
</asp:UpdatePanel>

按钮的代码

protected void btnBlock_Click(object sender,EventArgs e)
{        
    CtiWS.CtiWS CtiWS1 = new CtiWS.CtiWS();
    Response.Write("<script>alert('"+Convert.ToString(Session["BlockCalls"])+"')</script>");
    if (btnBlock.Text == "BlockCalls")
    {
        btnBlock.Text = "UnBlockCalls";
        CtiWS1.BlockCalls("","",HttpContext.Current.Session["HOSTID"].ToString()); //server block calls
    }
    else
    {
        btnBlock.Text = "BlockCalls";
        CtiWS1.BlockCalls("",HttpContext.Current.Session["HOSTID"].ToString()); //server unblock calls 
    }

}

解决方法

尝试这个

将ChildrenAsTriggers设置为true并在asp:AsyncPostBackTrigger中添加EventName =“Click”

<asp:UpdatePanel ID="updatePanel2" runat="server" UpdateMode="Conditional" 
                ChildrenAsTriggers="true">
   <ContentTemplate>
    <asp:Button ID="btnBlock" class="Button" Text="BlockCalls" runat="server"       
                 onclick="btnBlock_Click" Enabled="True" Width="100px" />  
   </ContentTemplate>
   <Triggers>
     <asp:AsyncPostBackTrigger ControlID="btnBlock" EventName="Click"/> 
    </Triggers>
</asp:UpdatePanel>
原文链接:https://www.f2er.com/aspnet/251171.html

猜你在找的asp.Net相关文章