Integrate Timer with UpdatePanel to async page update - ASP.NET
The Example show integration Timer with UpdatePanel to update page asynchronously.
By Mohd Zulkamal
NOTE : – If You have Found this post Helpful, I will appreciate if you can Share it on Facebook, Twitter and Other Social Media Sites. Thanks =)
The ASPX Page
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<!-- Interval time 5000 will be 5 second -->
<asp:Timer ID="Timer1" runat="server" Interval="5000" ontick="Timer1_Tick">
</asp:Timer>
<asp:Label ID="Label1" runat="server"></asp:Label>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" />
</Triggers>
</asp:UpdatePanel>
<asp:UpdateProgress ID="UpdateProgress1" DisplayAfter="10" runat="server" AssociatedUpdatePanelID="UpdatePanel1">
<ProgressTemplate>
<div style="position: absolute; top: 40%; left: 45%; background-color: #fffff0">
Please wait...
</div>
</ProgressTemplate>
</asp:UpdateProgress>
</div>
The Code Behind
protected void Timer1_Tick(object sender, EventArgs e)
{
if (ViewState["updateTime"] != null)
{
Label1.Text = "Page update " + (Convert.ToInt16(ViewState["updateTime"]) + 1) + " times";
ViewState["updateTime"] = (Convert.ToInt16(ViewState["updateTime"]) + 1).ToString();
}
else
{
Label1.Text = "Page update 1 times";
ViewState["updateTime"] = "1";
}
}
Output
By Mohd Zulkamal
NOTE : – If You have Found this post Helpful, I will appreciate if you can Share it on Facebook, Twitter and Other Social Media Sites. Thanks =)