Click here to Skip to main content
Click here to Skip to main content

Timer Control for web applications

, 23 Apr 2007 CPOL
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.

Comments and Discussions

 
GeneralMy vote of 5 PinprofessionalDan Randolph17-Aug-13 9:37 
QuestionWebTimer1.IsPostedBackByTimer value came false even for timer Post back Pinmemberprem466614-Aug-12 6:37 
GeneralMy vote of 5 PinmemberMember 88055004-Jun-12 2:14 
GeneralMy vote of 1 Pinmemberriyazb13-Jul-10 20:38 
QuestionHow to keep track of the start and stop timer duration? Pinmemberavishekrc17-Mar-10 6:52 
GeneralAyax Pinmembermbaocha6-May-09 18:39 
GeneralCheck out this... Pinmemberauthord30-Sep-08 6:31 
Generalsetting a time for my project Pinmembermohammadhussain19-May-08 20:33 
QuestionDo you have this code in AJAX PinmemberYossiKahlon13-Jul-07 10:52 
GeneralI hope I'm not just stupid! PinmemberMichael1015-Jun-07 18:03 
GeneralRe: I hope I'm not just stupid! PinmemberMichael1015-Jun-07 19:17 
GeneralRe: I hope I'm not just stupid! PinmemberDeepson Thomas5-Jun-07 20:45 
GeneralRe: I hope I'm not just stupid! Pinmembermanisha agarwal28-Aug-08 6:55 
Generalexception Pinmemberjijog27-Apr-07 21:59 
GeneralRe: exception PinmemberDeepson Thomas6-May-07 23:13 
Generalhi can i just use it to create a delay in my application Pinmemberrama charan26-Apr-07 22:17 
GeneralRe: hi can i just use it to create a delay in my application PinmemberDeepson Thomas6-May-07 23:15 
GeneralRe: hi can i just use it to create a delay in my application Pinmemberrama charan7-May-07 8:52 
GeneralRe: hi can i just use it to create a delay in my application Pinmemberraju jani22-Aug-14 20:40 
QuestionWhy does not a server control ? PinmemberMaxim Kurdukov18-May-06 20:09 
AnswerRe: Why does not a server control ? Pinmemberdeepson21-May-06 1: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.150327.1 | Last Updated 23 Apr 2007
Article Copyright 2006 by Deepson Thomas
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid