Click here to Skip to main content
11,925,896 members (59,797 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


38 bookmarked

Web Timer Control

, 7 Oct 2008 GPL3
Rate this:
Please Sign up or sign in to vote.
Provides a mechanism for executing a method at specified intervals
Figure: Timer GUI


Timer control is purely a Web-based control.

Timer Class

  • Provides a mechanism for executing a method at specified intervals.
  • Timer control'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


Timer control 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 DoPostBackOnTimeOut attribute is set to TRUE.

Properties & Definition


If set to true, Timer countdown starts immediately after page load.

If set it to false, Timer countdown 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.

To run Timer, this property needs to be set to true.


The Timer control runs based on a JavaScript. We can't claim that Timer control always maintains perfect timings. It might miss a couple of seconds.

If ServerSideTimeSynchronize is 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.


Timer StopWatch is a JavaScript based program. When the interval is reached, it enables the client callback functions.

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 TimeOut event with full post back. Now, you can modify the contents or redirect to another page.

This won't create a postback for the IntervalReached event.


It disables the mouse right click. Mouse right click affects the timer stopwatch. So it is recommended to set DisableRightClick to true.

If you don't want to disable the mouse right click, then set ServerSideTimeSynchronize to true.

This is done so that it updates the Timer StopWatch for every interval.


Interval is defined in seconds.

Raises an IntervalReached event on your application when a specified period of time has elapsed.


TimeOut is defined in seconds.

Raises a TimeOut event on your application when a TimeOut has elapsed.

It is raised only once for entire Timer period.

***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"
    TimeOut="9" OnIntervalReached="Timer1_IntervalReached"
    OnTimeOutOccurred="Timer1_TimeOutOccurred" IsAutoStart="true"

Using a Timer Control

Suppose you want to update the date time on the server for every 10 seconds.

You could create a Timer to periodically update date time on the SQL server.

Specifying Time on a Timer Control

See Interval and Timeout properties. Both are defined in seconds.

Specifying Themes on a Timer Control

Timer control inherits Label properties. So you can use it like ASP.NET Label.

Specifying Stop Watch Visibility on a Timer Control

If you don't want to display the stopwatch/countdown, you can set visibility to false. But Timer controls runs regardless of visible property. Only Enable property disables the Timer control.


This article, along with any associated source code and files, is licensed under The GNU General Public License (GPLv3)


About the Author

Prem Rajadattan
United States United States

You may also be interested in...

Comments and Discussions

QuestionThanks Pin
A. Najafzadeh10-Jul-15 8:35
memberA. Najafzadeh10-Jul-15 8:35 
QuestionNot Working in WebApplication Pin
Aytha22-Jan-14 6:33
memberAytha22-Jan-14 6:33 
Questionissue when using the control Pin
the algabban29-May-12 16:56
memberthe algabban29-May-12 16:56 
QuestionHow to pause the timer Pin 21:33 21:33 
QuestionServer Error Pin
mamta20121-Mar-12 19:37
membermamta20121-Mar-12 19:37 
AnswerRe: Server Error Pin 21:34 21:34 
GeneralRe: Server Error Pin
the algabban29-May-12 16:57
memberthe algabban29-May-12 16:57 
Generaladd repeatable properties ! Pin
ikuto tohoin25-Jan-11 18:01
memberikuto tohoin25-Jan-11 18:01 
GeneralTimer Pin
claudiajs27-May-10 23:30
memberclaudiajs27-May-10 23:30 
GeneralAdd Days Pin
claudiajs25-May-10 0:07
memberclaudiajs25-May-10 0:07 
GeneralRe: Add Days Pin
Prem Rajadattan25-May-10 13:04
memberPrem Rajadattan25-May-10 13:04 
QuestionHow to keep track of the start and stop timer duration? Pin
avishekrc17-Mar-10 6:59
memberavishekrc17-Mar-10 6:59 
GeneralThats Great Pin
AMK_SDK30-Sep-09 22:43
memberAMK_SDK30-Sep-09 22:43 
GeneralGood article Pin
Donsw27-Jan-09 8:27
memberDonsw27-Jan-09 8:27 
GeneralUrgent Help Needed Pin
Member 421903222-Apr-09 18:56
memberMember 421903222-Apr-09 18:56 
Hi there,
I am badly in need of timer control. After searching thru, I found out that this can be used with few modifications.
First of all thanks to the author, for providing this source code.
I am a very newbie.. When I try to add this code, it gives below error

Element 'Timer' is not a known element. This can occur if there is a compilation error in the Web site.

The type or namespace name 'CodeControls' could not be found (are you missing a using directive or an assembly reference?)

There is no APP_Code folder in my project.
So what should I do? Where should I place timer1.Cs file?/

Urgent help needed.

Thanks very much in advance
GeneralRe: Urgent Help Needed Pin
Aytha22-Jan-14 6:34
memberAytha22-Jan-14 6:34 
GeneralNice control, but i have a question Pin
ewanko21827-Oct-08 2:57
memberewanko21827-Oct-08 2:57 
GeneralIts Interesting Pin
shiva.jayaraman21-Oct-08 0:52
membershiva.jayaraman21-Oct-08 0:52 
GeneralRe: Its Interesting Pin
authord21-Oct-08 20:27
memberauthord21-Oct-08 20:27 
Generalseems interesting Pin
saber_solomon6-Oct-08 23:08
membersaber_solomon6-Oct-08 23:08 
GeneralRe: seems interesting Pin
authord7-Oct-08 8:23
memberauthord7-Oct-08 8:23 
GeneralRe: seems interesting Pin
saber_solomon7-Oct-08 21:55
membersaber_solomon7-Oct-08 21:55 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.151126.1 | Last Updated 7 Oct 2008
Article Copyright 2008 by Prem Rajadattan
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid