ASP.NET AJAX Timer Control-Here we go
The timer control is one of the ASP.NET AJAX (ATLAS ) controls, We could use the timer control for several usage, such as setting a clock on your page, updating the price of a company’s quote each while for example, and more.
The process of doing this now is so simple I remember the time when we did that using javascript and it was not that simple,.
First you have to add a reference to the Microsoft.Web.Atlas.dll located in the folder you have installed the ATLAS components to.
After that we will drag a ScriptManager control to our page and rename it to scriptManager.
Note: the ScriptManager should be the first ATLAS control located on your page else an error such the following will face you for example
An UpdatePanel requires a ScriptManager on the page. The ScriptManager must exist before the UpdatePanels.
Anyways, after dragging the ScriptManager control consider setting the EnablePartialRendering property to true
The next step is dragging an UpdatePanel to your content area, then add a ContentTemplate tag to it add more controls inside our UpdatePanel
For the propose of this post we will add 2 controls a Label and a Timer Control
Our label will be called lblDate
The timer will be timerControl
As a Timer the control is provided with an Interval property and a Tick Event.
We will set the interval for 1000 so our timer will fire the Tick event every 1 second to update the Label with the server time.
protected void timerControl_Tick(object sender, EventArgs e)
{
lblDate.Text = DateTime.Now.ToString();
}
When we run our code the Label will appear empty after 1 second it will be get updated with the server date and time.
With the existence of the Timer control things now are very simple and provides to our hands a usable web page that could do more than updating a label.
Enjoy you night guys ;)