I have an UpdateProgress
and I'm trying to show a loading gif
while post back
but this code doesn't work when I click the button.
There is nothing happens with with this code and no post back on button click.
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<asp:UpdateProgress ID="UpdateProgress1" runat="server" AssociatedUpdatePanelID="UpdatePanel1" DynamicLayout="true">
<ProgressTemplate>
<asp:Image ID="ImageWait" runat="server" ImageUrl="../images/wait.gif" />
</ProgressTemplate>
</asp:UpdateProgress>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Button ID="ButtonSave" runat="server" Text="Save" OnClick="ButtonSave_Click" ValidationGroup="Valid1" />
</ContentTemplate>
</asp:UpdatePanel>
protected void ButtonSave_Click(object sender, EventArgs e)
{
// Some code
}
How can I fix this?
Manually trigger AsyncPostBackTrigger to your controls inside UpdatePanel and give the ControlID and EventName that will fire:
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional" > </ContentTemplate> <asp:Button ID="ButtonSave" runat="server" Text="Save" OnClick="ButtonSave_Click" /> </ContentTemplate> <Triggers> <asp:AsyncPostBackTrigger ControlID="ButtonSave" EventName="Click" /> </Triggers> </asp:UpdatePanel>
Give an associated UpdatePanel's ID to UpdateProgress:
<asp:UpdateProgress ID="UpdateProgress1" runat="server" AssociatedUpdatePanelID="UpdatePanel1">
And you can test its working in events using System.Threading.Thread.Sleep(3000);
:
protected void ButtonSave_Click(object sender, EventArgs e) { // delay it for 3 milliseconds System.Threading.Thread.Sleep(3000); //... Here will be your logic }
by default (whan no value is set in the UpdateProgress control)
DisplayAfter="500"
If your postback is "too fast", UpdateProgress will not show... Try setting it to:
DisplayAfter="1"
to check if it's working, and than set your desired value
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.