Asp.Net Ajax Timer Control Demo

Leave a Comment

While working with asynchronous postbacks we might want these postback to happen after a specific interval, this can be done using Timer control.

This has an event called “OnTick” that is used to specify a server side event that fires after every specified interval in the “Interval” property.

Deafult.aspx
<form id="form1" runat="server">
    <div>
    <p>Timer example: Please wait for 5 seconds and timer appears.</p>
        <asp:ScriptManager runat="server" ID="SM1" />
        <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
            <ContentTemplate>
                <asp:Label ID="lblMessage" runat="server" EnableViewState="false" />
                <asp:Timer ID="Timer1" runat="server" Interval="5000" OnTick="TimerTick" />
            </ContentTemplate>
        </asp:UpdatePanel>
    </div>
    </form>

Default.aspx.cs
protected void TimerTick(object sender, EventArgs e)
    {
        lblMessage.Text = DateTime.Now.ToString();
    }

Download Source Code

0 comments:

Post a Comment