I have a panel that set its visibility false when page loading. When the user clicks a button, the panel should be visible or invisible based on some database result. This is working as expected. My form looks like below.
<form id="form1" runat="server"><asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager><asp:Panel ID="Panel1" Visible="false" runat="server"><asp:UpdatePanel ID="UpdatePanel1" runat="server"><ContentTemplate><asp:Label ID="lblName" runat="server" Text="Name"></asp:Label><asp:TextBox ID="txtName" runat="server"></asp:TextBox></ContentTemplate></asp:UpdatePanel></asp:Panel><br /><hr /><asp:Button ID="btnGetData" runat="server" Text="Get Data" OnClick="btnGetData_Click" /></form>
The CodeBehind
protected void btnGetData_Click(object sender, EventArgs e)
{
Thread.Sleep(5000);
Panel1.Visible = !(Panel1.Visible);
}The problem is that the DB operation takes some time (mimicked by Thread.sleep in this example) and the page is frozen during this time. I want a “wait message” to be displayed to the user till the postback complete. Here is what I tried. The following shows the “wait message” but now the panel visibility cannot be toggled. It is stuck at the initial value. Please help
<form id="form1" runat="server"><asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager><asp:Panel ID="Panel1" Visible="false" runat="server"><asp:UpdatePanel ID="UpdatePanel1" runat="server"><ContentTemplate><asp:Label ID="lblName" runat="server" Text="Name"></asp:Label><asp:TextBox ID="txtName" runat="server"></asp:TextBox></ContentTemplate></asp:UpdatePanel></asp:Panel><br /><hr /><asp:UpdatePanel ID="UpdatePanel2" runat="server"><ContentTemplate><asp:Button ID="btnGetData" runat="server" Text="Get Data" OnClick="btnGetData_Click" /></ContentTemplate></asp:UpdatePanel><asp:UpdateProgress ID="UpdateProgress1" runat="server"><ProgressTemplate><div class="updateProgress">please wait...<br /><img alt="Wait image" src="Resources/timer.gif" /> /></div></ProgressTemplate></asp:UpdateProgress></form>