Sunday, 5 January 2014

Integrate Timer with UpdatePanel to async page update - ASP.NET

Leave a Comment
The Example show integration Timer with UpdatePanel to update page asynchronously.

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
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 =)

0 comments:

Post a Comment

Subscribe to our newsletter to get the latest updates to your inbox.

Your email address is safe with us!




Founder of developersnote.com, love programming and help others people. Work as Software Developer. Graduated from UiTM and continue study in Software Engineering at UTMSpace. Follow him on Twitter , or Facebook or .



Powered by Blogger.