Click here to Skip to main content
15,867,453 members
Articles / Web Development / ASP.NET
Article

Timer Control for web applications

Rate me:
Please Sign up or sign in to vote.
3.26/5 (18 votes)
23 Apr 2007CPOL2 min read 112.2K   6K   37   22
Web based timer control in asp.net

Introduction

A web timer control that can be used to execute certain functionalities in a regular interval. As per my control, the scope of functionality involves posting back the web page and triggering the execution of a client side JavaScript method.

In web application environment we lack a proper timer control just like we have in windows application development environment. This is one of the main reasons why I went in search of a web based timer control. I tried a lotz of search in net to find a suitable web based timer control code or for an idea which we can use in web application and can be controlled from the code behind, and i ended up in codeproject. I got an article by TCDooM where he posted one of his creations i.e. a custom timer control which we can use in web apps. Thanx TCDooM :)

His article and his work really helped me to complete this control. The base of my control is the contribution of TCDooM's work.

Tech Talk

This control is pretty easy to use and you can make use of it with the help of a few properties. Just add the files into your page and then drag and drop to any page and call the timer object.

I am not going to explain the code because the code is that much simple and straight forward that any newbie in ASP.Net can understand.
So let me give an overview

  1. First use the namespace DControls
  2. This web timer has mainly two functions.
    Either it will post back the parent page in regular intervals or we can execute a client side JavaScript function in regular intervals.

    a. WebTimer1.SetTimerAction = Timer.TimerAction.Postback_Page;<br />b. WebTimer1.SetTimerAction = Timer.TimerAction.Execute_JSFunction;<br />i. WebTimer1.SetJSFunctionName = "ClientJSFunction()";

3. Timer will be disabled by default.

WebTimer1.Enabled=true;
4. Intervals you can specify in minutes or seconds or milliseconds. Minute is default. Then set the interval duration.

WebTimer1.Interval = 30;<br />WebTimer1.SetIntervalMode = Timer.IntervalMode.Seconds;5. If you set the timer action as Postback_Page then in the code behind you have to use a property called IsPostedBackByTimer which will tell you whether the page is posted back by timer or by any other events.

if(Page.IsPostBack)<br />{<br />if(WebTimer1.IsPostedBackByTimer)<br />{<br />Response.Write("Page Posted Back By WebTimer");<br />}<br />}

Currently I used C# but anybody can easily convert into vb.net.

Don't hesitate to contact me if you need any help or if you have any suggestions or comments

so..... happy programming ;)

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
India India
He has got software development experience of 6+ years in ASP.NET , C# , VB.Net, ASP 3.0, PHP, MS SQL, WebServices and XML. He spends his time reading / writing technical articles, wandering thru net for interesting and weird technologies. He enjoys music all the time and has a passion of watching sci-fi and classic Hollywood movies.

Comments and Discussions

 
GeneralMy vote of 5 Pin
Dan Randolph17-Aug-13 8:37
Dan Randolph17-Aug-13 8:37 
GeneralRe: My vote of 5 Pin
Deepson Thomas1-May-16 7:22
Deepson Thomas1-May-16 7:22 
QuestionWebTimer1.IsPostedBackByTimer value came false even for timer Post back Pin
prem466614-Aug-12 5:37
prem466614-Aug-12 5:37 
GeneralMy vote of 5 Pin
Member 88055004-Jun-12 1:14
Member 88055004-Jun-12 1:14 
GeneralMy vote of 1 Pin
riyazb13-Jul-10 19:38
riyazb13-Jul-10 19:38 
QuestionHow to keep track of the start and stop timer duration? Pin
avishekrc17-Mar-10 5:52
avishekrc17-Mar-10 5:52 
GeneralAyax Pin
mbaocha6-May-09 17:39
mbaocha6-May-09 17:39 
GeneralCheck out this... Pin
Prem Rajadattan30-Sep-08 5:31
Prem Rajadattan30-Sep-08 5:31 
Generalsetting a time for my project Pin
mohammadhussain19-May-08 19:33
mohammadhussain19-May-08 19:33 
QuestionDo you have this code in AJAX Pin
YossiKahlon13-Jul-07 9:52
YossiKahlon13-Jul-07 9:52 
Hi,
I am not sure that I ask the right question.
when using Microsoft Ajax I know that client script should be registered with the ScriptManager. Do you have this code with the Ajax support?

Thanks,
Yossi
GeneralI hope I'm not just stupid! Pin
Michael1015-Jun-07 17:03
Michael1015-Jun-07 17:03 
GeneralRe: I hope I'm not just stupid! Pin
Michael1015-Jun-07 18:17
Michael1015-Jun-07 18:17 
GeneralRe: I hope I'm not just stupid! Pin
Deepson Thomas5-Jun-07 19:45
Deepson Thomas5-Jun-07 19:45 
GeneralRe: I hope I'm not just stupid! Pin
manisha agarwal28-Aug-08 5:55
manisha agarwal28-Aug-08 5:55 
Generalexception Pin
jijog27-Apr-07 20:59
jijog27-Apr-07 20:59 
GeneralRe: exception Pin
Deepson Thomas6-May-07 22:13
Deepson Thomas6-May-07 22:13 
Generalhi can i just use it to create a delay in my application Pin
rama charan26-Apr-07 21:17
rama charan26-Apr-07 21:17 
GeneralRe: hi can i just use it to create a delay in my application Pin
Deepson Thomas6-May-07 22:15
Deepson Thomas6-May-07 22:15 
GeneralRe: hi can i just use it to create a delay in my application Pin
rama charan7-May-07 7:52
rama charan7-May-07 7:52 
GeneralRe: hi can i just use it to create a delay in my application Pin
raju jani22-Aug-14 19:40
raju jani22-Aug-14 19:40 
QuestionWhy does not a server control ? Pin
Maxim Kurdukov18-May-06 19:09
Maxim Kurdukov18-May-06 19:09 
AnswerRe: Why does not a server control ? Pin
Deepson Thomas21-May-06 0:40
Deepson Thomas21-May-06 0:40 

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.