Figure: Timer GUI
Timercontrol is purely a Web-based control.
- Provides a mechanism for executing a method at specified intervals.
Timercontrol's stopwatch counts downwards from 'X' to ZERO time for measuring elapsed time.
Notifies your application when a specified period of time has elapsed. It is triggered through a client callback method. So you can't update the page contents from this event.
protected void Timer1_IntervalReached(object sender, CodeControls.TimerEventArgs e)
Notifies your application when a specified Time Out has been reached.
protected void Timer1_TimeOutOccurred(object sender, CodeControls.TimerEventArgs e)
Figure: Properties and Events
Timercontrol is built on Client CallBack technique. So no postback is required for notifying your application when interval or timeout is reached.
Since the mechanism implements client callback method, you are limited to the following:
- You can perform database operations.
- You can't redirect the current page
- You can't modify the content of the current page.
- You can have access to the cookies and cache.
- You can't store the value in the session. This is because posted session values are available after the post back.
To overcome this limitation, this control provides a mechanism to do a full post back on Time Out.
So you can modify, redirect the current page if
DoPostBackOnTimeOutattribute is set to
Properties & Definition
If set to
Timercountdown starts immediately after page load.
If set it to
Timercountdown won't be triggered at the page load. You should call
Timer1.ManualStart() method in your page to trigger the Timer.
If it is set to
false, it won't register the related script to the page.
Timer, this property needs to be set to
Timercontrol always maintains perfect timings. It might miss a couple of seconds.
ServerSideTimeSynchronizeis set to
true, the time calculations are based on the server. After each interval, the timer gets the amount of Time left from the server and updates the stop watch.
This is will lead to slight bumps in the countdown.
So no post back is required for notifying your application when interval or timeout is reached. As a result of this
ClientCallBack, you can't modify the page contents.
This property allows control to trigger a
TimeOutevent with full post back. Now, you can modify the contents or redirect to another page.
This won't create a postback for the
It disables the mouse right click. Mouse right click affects the timer stopwatch. So it is recommended to set
If you don't want to disable the mouse right click, then set
This is done so that it updates the
Timer StopWatchfor every interval.
Interval is defined in seconds.
IntervalReachedevent on your application when a specified period of time has elapsed.
TimeOutis defined in seconds.
TimeOutevent on your application when a
It is raised only once for entire
***Timer is set to last interval time, when a postback occurs.
Creating a New Timer Control
Add the following to your *.aspx page.
<%@ Register Namespace="CodeControls" TagPrefix="cc" %>
<cc:Timer ID="Timer1" runat="server" DoPostBackOnTimeOut="false" Font-Names="Verdana"
Font-Size="68px" ForeColor="#FF8000" Interval="5" ServerSideTimeSynchronize="True"
Using a Timer Control
Suppose you want to update the date time on the server for every 10 seconds.
You could create a
Timerto periodically update date time on the SQL server.
Specifying Time on a Timer Control
Timeoutproperties. Both are defined in seconds.
Specifying Themes on a Timer Control
Labelproperties. So you can use it like ASP.NET
Specifying Stop Watch Visibility on a Timer Control
If you don't want to display the stopwatch/countdown, you can set visibility to
Timercontrols runs regardless of visible property. Only
Enableproperty disables the