Home > DeveloperSection > Articles > ASP.Net AJAX Server Control: Timer

ASP.Net AJAX Server Control: Timer


AJAX AJAX 
Ratings:
1 Comment(s)
 5990  View(s)
Rate this:

ASP.Net AJAX Server Control: Timer

Timer: The timer control will execute client side event s at specific interval and allows specific part so your page to update or refresh at these moments.

How we implement the Timer server control

 

Step1: we use the following control on aspx page

 

Example:

<body>

  <form id="form1" runat="server">

  <div>

    <%--Using ScriptManger Control--%>

    <asp:ScriptManager ID="ScriptManager1" runat="server">

    </asp:ScriptManager>

    <%--Using UpdatePanel Control--%>

    <asp:UpdatePanel ID="UpdatePanel1" runat="server">

    <ContentTemplate>

    <%-- Using Label And Timer Control inside UpdatePanel--%>

    <asp:Label ID="lblDateTime" runat="server" Text=""> </asp:Label>

    <asp:Timer ID="Timer1"runat="server"Interval="9000"OnTick= "Timer1_Tick">

    </asp:Timer>

    </ContentTemplate>

    </asp:UpdatePanel>

  </div>

  </form>

</body>

 

Step2: We write the following code on Timer1_Tick event.

 

Example:

protected void Page_Load(object sender, EventArgs e)

{

if (!Page.IsPostBack)

{

lblDateTime.Text ="Start DateTime: "+ DateTime.Now.ToString();

}

}

protected void Timer1_Tick(object sender, EventArgs e)

{

lblDateTime.Text ="By Timer: "+ DateTime.Now.ToString();

}

 

Step3: Run the project

 

Output:

After Sometimes, the output is:

 

 This is the simple example of Timer and UpdatePanel control, how we use these control in our web based project or window based project.


Thanks..

By Sunil Singh on   2 months ago

This article is truly nice.


Don't want to miss updates? Please click the below button!

Follow MindStick