Click here to Skip to main content
11,634,796 members (68,229 online)
Click here to Skip to main content

Timer Control for web applications

, 23 Apr 2007 CPOL 86.5K 5.4K 37
Rate this:
Please Sign up or sign in to vote.
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 Smile | :)

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;
    b. WebTimer1.SetTimerAction = Timer.TimerAction.Execute_JSFunction;
    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;
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)
{
if(WebTimer1.IsPostedBackByTimer)
{
Response.Write("Page Posted Back By WebTimer");
}
}

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 Wink | ;)

License

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

Share

About the Author

Deepson Thomas
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.

You may also be interested in...

Comments and Discussions

 
GeneralMy vote of 5 Pin
Dan Randolph17-Aug-13 8:37
professionalDan Randolph17-Aug-13 8:37 
QuestionWebTimer1.IsPostedBackByTimer value came false even for timer Post back Pin
prem466614-Aug-12 5:37
memberprem466614-Aug-12 5:37 
GeneralMy vote of 5 Pin
Member 88055004-Jun-12 1:14
memberMember 88055004-Jun-12 1:14 
GeneralMy vote of 1 Pin
riyazb13-Jul-10 19:38
memberriyazb13-Jul-10 19:38 
QuestionHow to keep track of the start and stop timer duration? Pin
avishekrc17-Mar-10 5:52
memberavishekrc17-Mar-10 5:52 
GeneralAyax Pin
mbaocha6-May-09 17:39
membermbaocha6-May-09 17:39 
GeneralCheck out this... Pin
authord30-Sep-08 5:31
memberauthord30-Sep-08 5:31 
Generalsetting a time for my project Pin
mohammadhussain19-May-08 19:33
membermohammadhussain19-May-08 19:33 
QuestionDo you have this code in AJAX Pin
YossiKahlon13-Jul-07 9:52
memberYossiKahlon13-Jul-07 9:52 
GeneralI hope I'm not just stupid! Pin
Michael1015-Jun-07 17:03
memberMichael1015-Jun-07 17:03 
GeneralRe: I hope I'm not just stupid! Pin
Michael1015-Jun-07 18:17
memberMichael1015-Jun-07 18:17 
GeneralRe: I hope I'm not just stupid! Pin
Deepson Thomas5-Jun-07 19:45
memberDeepson Thomas5-Jun-07 19:45 
GeneralRe: I hope I'm not just stupid! Pin
manisha agarwal28-Aug-08 5:55
membermanisha agarwal28-Aug-08 5:55 
Generalexception Pin
jijog27-Apr-07 20:59
memberjijog27-Apr-07 20:59 
GeneralRe: exception Pin
Deepson Thomas6-May-07 22:13
memberDeepson 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
memberrama 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
memberDeepson 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
memberrama 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
memberraju jani22-Aug-14 19:40 
QuestionWhy does not a server control ? Pin
Maxim Kurdukov18-May-06 19:09
memberMaxim Kurdukov18-May-06 19:09 
AnswerRe: Why does not a server control ? Pin
deepson21-May-06 0:40
memberdeepson21-May-06 0:40 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    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.150728.1 | Last Updated 23 Apr 2007
Article Copyright 2006 by Deepson Thomas
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid