articles

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

ASP.Net AJAX Server Control: Timer

Amit Singh 7866 05-Oct-2010

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();
}
}
protectedvoid Timer1_Tick(object sender, EventArgs e)
{
lblDateTime.Text ="By Timer: "+ DateTime.Now.ToString();
}

  Step3: Run the project 

Output:

ASP.Net AJAX Server Control: Timer

After Sometimes, the output is:

 

ASP.Net AJAX Server Control: Timer This is the simple example of Timer and UpdatePanel control, how we use these control in our web based project or window based project.



Updated 04-Mar-2020

Leave Comment

Comments

Liked By