Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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 
    }

}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
733 views
Welcome To Ask or Share your Answers For Others

1 Answer

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>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...