Click here to Skip to main content
15,891,529 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I use an UpdatePanel with some controls. When I click on the button, it creates a sleep. In this time I click on second button, its handlers execute async successfully. But one of the labels does not get updated. Why?

ASP.NET
<body>
    <form id="form1"  runat="server">
        <asp:ScriptManager ID="ScriptManager1" runat="server">
        
        <asp:UpdatePanel ChildrenAsTriggers="true" ID="UpdatePanel1"  runat="server" >
            <contenttemplate>
                    <asp:Button runat="server" Text="PostBackFirst" ID="btnPostF" 
                        onclick="btnPostF_Click"/> 
                    <asp:Button runat="server" Text="PostBackSecond" ID="btnPostS"
                        onclick="btnPostS_Click"/> 
                    <asp:Button runat="server" Text="AbortPostBack" ID="btnAbort"
                        OnClientClick="Sys.WebForms.PageRequestManager.getInstance().abortPostBack();
                        alert('Postback Cancelled');"/>
                    <asp:Label ID="Label1" runat="server" Text="">            
                    <asp:Label ID="Label2" runat="server" Text="">            
            </contenttemplate>
            
    </form>
</body>



C#
protected void btnPostF_Click(object sender, EventArgs e)
       {
           System.Threading.Thread.Sleep(4000);
           Label1.Text = "PostBack 1 Completed";

       }

       protected void btnPostS_Click(object sender, EventArgs e)
       {
           System.Threading.Thread.Sleep(4000);
           Label2.Text = "PostBack 2 Completed";

       }
Posted
Updated 25-Aug-11 23:19pm
v3
Comments
Herman<T>.Instance 22-Aug-11 13:46pm    
which one does not update?
[no name] 22-Aug-11 14:56pm    
i have two lable in update panel ,when btnPostF button click and then btnPostS button,
only lable2 to update in update panel and lable2 do not update!!
Herman<T>.Instance 23-Aug-11 3:34am    
does your async really work? Something tells me that the 4 second sleep is standing in the way. try clicking both buttons with a pause of 5 seconds between clicking

i think autopostback=true for the two labels will work fine..
 
Share this answer
 
v2
Hi,

Things are behaving correctly. Let me explain how it is working-

Suppose you click on the first button, on click it comes to the click event and it sleeps for 4 seconds. Now while its in sleep if you abort the post back by clicking third button. Then it will not proceed with the event. If you wait for 4 second then you can see the label is updated with the desired value. Same with second button.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900