小编典典

按钮单击在更新面板中不起作用

ajax

当我在“更新”面板中使用“按钮”时,它不会触发点击事件,但在更新面板之外,它可以工作。
这是代码

<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 
    }

}

阅读 251

收藏
2020-07-26

共1个答案

小编典典

试试这个

ChildrenAsTriggerstrue和附加EventName="Click"asp:AsyncPostBackTrigger

<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>
2020-07-26