9

When I use Button inside Update panel it doesnot fire click event but outside the update panel it works.
here is the code

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

code for button is

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 
    }

}
Humayun Shabbir
  • 2,961
  • 4
  • 20
  • 33
user3713775
  • 168
  • 3
  • 4
  • 14

1 Answers1

10

Try this

set ChildrenAsTriggers to true and add EventName="Click" in 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>
Sid M
  • 4,354
  • 4
  • 30
  • 50
  • 2
    Why do you need a trigger for the button? It's in the Update Panel - ChildrenAsTriggers is true - you don't need it. – Martin Smellworse Aug 01 '14 at 08:48
  • 1
    @MartinSmellworse because the ChildrenAsTriggers is a full postback trigger request. If you want to do an Async trigger, you need to be specific – Fandango68 Jul 05 '16 at 06:36