Click here to Skip to main content
13,146,402 members (48,163 online)
Click here to Skip to main content
Add your own
alternative version


45 bookmarked
Posted 30 Jul 2006

A Stoppable Timer Control for ASP.NET Atlas

, 30 Jul 2006
Rate this:
Please Sign up or sign in to vote.
This article presents a timer control that resolves an issue with the Atlas Timer server control. The issue being the Atlas TimerControl cannot be stopped from the server side code.


ASP.NET Atlas has a timer server control which periodically postbacks to the server. However, the TimerControl has a bug that prevents it to be stopped from server side code during partial rendering. Time and again, I encounter the question in Atlas forums which ask for a workaround to this bug. This article is based on my post in Atlas forums, and has detailed explanation on how to solve this problem. Hopefully, the issue will be resolved in a future version of Atlas.

Using the Code

Here are the steps you must take to use this control:

  1. Copy the StoppableTimer.cs file to the App_Code directory of your web site.
  2. Modify the web.config file to add the following element:
                <add tagType="Microsoft.Web.UI.Controls.TimerControl" 
  3. The configuration setting automatically allows your class to be used instead of the Atlas TimerControl without any changes to existing web pages. In a new page, you can continue to use the control using the following syntax:
    <atlas:TimerControl ID="Timer1" 
          runat="server" Interval="500" OnTick="Timer1_Tick" 
          Enabled="false" />
  4. If the bug is fixed in a future CTP, you can just remove the configuration setting, and everything will work as it is.

How it Works

There are two problems with the Atlas server control which causes this bug:

  1. The control does not generate any ID for the timer.

  2. It does not try to stop the timer in response to postbacks or callbacks.

The timer control presented in the article modifies the rendering of the TimerControl as follows:

protected override void RenderScript(ScriptTextWriter writer)
  if (!IsPageInPartialRendering)
    writer.WriteAttributeString("id", this.UniqueID);
    writer.WriteAttributeString("enabled", this.Enabled.ToString().ToLower());
    writer.WriteAttributeString("target", this.UniqueID);
    writer.WriteAttributeString("eventArgument", string.Empty);

As you can see, the control renders the XML-Script except for partial rendering. During partial rendering, the timer object on the client web page is not destroyed, so all that needs to be done is to enable or disable the client-side object. This is done in the OnPreRender method:

protected override void OnPreRender(EventArgs e)
   if (IsPageInPartialRendering)
     string scriptSnippetFormat = "$object(\"{0}\").set_enabled({1});";
     string scriptSnippet = 



The only remaining interesting part of the code is obtaining the instance of the script manager on the page and finding whether the ScriptManager is in partial rendering mode:

bool IsPageInPartialRendering
      ScriptManager manager = ScriptManager.GetCurrent(this.Page);
      return (manager != null && manager.IsInPartialRenderingMode);


This is a quick fix for a bug that exist in Atlas as I know in June CTP. It may be fixed in the coming releases of Atlas. Fortunately, if you use the fix as described, all you will need to do is to change the configuration setting, and you don't need to change any of the source code of any page.


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


About the Author

Rama Krishna Vavilala
United States United States
No Biography provided

You may also be interested in...


Comments and Discussions

GeneralNot cross-browser compatible Pin
Xpnctoc30-Sep-08 5:21
memberXpnctoc30-Sep-08 5:21 
Generaltype or namespace not found Pin
blumonde15-Dec-06 4:56
memberblumonde15-Dec-06 4:56 
GeneralRe: type or namespace not found Pin
static426-Jan-07 8:57
memberstatic426-Jan-07 8:57 
GeneralRe: type or namespace not found Pin
tbenami31-Jul-08 6:45
membertbenami31-Jul-08 6:45 
Generalchanging interval Pin
rodrigo.argenta14-Nov-06 8:06
memberrodrigo.argenta14-Nov-06 8:06 
GeneralIt did not work with me!! Pin
AL3600B10-Nov-06 23:53
memberAL3600B10-Nov-06 23:53 
arinpcssouth8-Nov-06 7:05
memberarinpcssouth8-Nov-06 7:05 
GeneralYou are a genius Pin
levalencia8-Nov-06 5:46
memberlevalencia8-Nov-06 5:46 
GeneralThanks! Pin
Artem L6-Nov-06 2:38
memberArtem L6-Nov-06 2:38 
GeneralOutstanding Pin
beep29-Oct-06 17:43
memberbeep29-Oct-06 17:43 
QuestionChange interval? Pin
MDominik1320-Oct-06 5:21
memberMDominik1320-Oct-06 5:21 
AnswerRe: Change interval? Pin
sidvivious25-Oct-06 5:54
membersidvivious25-Oct-06 5:54 
GeneralRe: Change interval? Pin
MDominik1325-Oct-06 10:34
memberMDominik1325-Oct-06 10:34 
QuestionRe: Change interval? Pin
ziwar30-Oct-06 1:02
memberziwar30-Oct-06 1:02 
QuestionMater page problem Pin
manudea16-Oct-06 7:53
membermanudea16-Oct-06 7:53 
AnswerRe: Mater page problem Pin
Rama Krishna Vavilala16-Oct-06 8:40
memberRama Krishna Vavilala16-Oct-06 8:40 
GeneralProblem Pin
srinivas7g9-Oct-06 6:56
membersrinivas7g9-Oct-06 6:56 
GeneralRe: Problem Pin
megagreg11-Oct-06 8:40
membermegagreg11-Oct-06 8:40 
GeneralRe: Problem Pin
srinivas7g11-Oct-06 16:00
membersrinivas7g11-Oct-06 16:00 
GeneralSolves a major problem Pin
megagreg6-Oct-06 9:44
membermegagreg6-Oct-06 9:44 
GeneralYou got my 5! Pin
breakpoint20-Sep-06 22:22
memberbreakpoint20-Sep-06 22:22 
GeneralExcellent Pin
eef19-Sep-06 23:29
membereef19-Sep-06 23:29 
GeneralI can´t make it work Pin
soledadm18-Sep-06 8:02
membersoledadm18-Sep-06 8:02 
GeneralRe: I can´t make it work Pin
Rama Krishna Vavilala18-Sep-06 8:25
memberRama Krishna Vavilala18-Sep-06 8:25 
GeneralRe: I can´t make it work Pin
soledadm19-Sep-06 8:46
membersoledadm19-Sep-06 8:46 

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.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.170915.1 | Last Updated 30 Jul 2006
Article Copyright 2006 by Rama Krishna Vavilala
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid