Timer Control Scenario
Use the Timer control when you want to do the following:
Update the contents of one or more UpdatePanel controls on a regular basis without refreshing the entire Web page.
Runs the code on the server whenever a Timer control causes a postback.
Synchronizes the entire Web page to a WEB server at defined intervals.
Background
A Timer control is a server control that embeds a JavaScript component into a Web page. When the time interval defined in the Interval property is passed, the JavaScript component initiates a postback from the browser. You can set the properties of the Timer control in code that runs on the server, and these properties are passed to that JavaScript component.
When you use the Timer control, you must include an instance of the ScriptManager class in the Web page.
If the postback was started by a timer control, the timer control will raise the Tick event on the server. When a page is sent to the server, you can create an event handler for the Tick event to perform some action.
Set the Interval property to specify how often the postback occurs, and the set Enabled property to turn the Timer on or off. The Interval property is defined in milliseconds, with a default value of 60,000 milliseconds (that is, 60 seconds).
Description
Setting the Interval property of a Timer control to a smaller value results in a large amount of traffic sent to the WEB server. You can use the Timer control to refresh content only as often as you want.
If different UpdatePanel controls must be updated at different intervals, you can include multiple Timer controls on the Web page. Alternatively, you can use a single instance of a Timer control as a trigger for multiple UpdatePanel controls in a Web page.
Using the Timer control inside a UpdatePanel control
When a timer control is contained inside a UpdatePanel control, the timer control is automatically used as a trigger for the UpdatePanel control. You can override this behavior by setting the Childrenastriggers property of the UpdatePanel control to false.
For the timer control inside the UpdatePanel control, recreate the JavaScript Timer component only when each postback completes. Therefore, the timing interval does not start until the page returns from a postback. For example, if the Interval property is set to 60,000 milliseconds (60 seconds), but it takes 3 seconds to complete a postback, the next postback will occur after 63 seconds of the previous postback.
The following example shows how to include a Timer control in a UpdatePanel control.
<asp:ScriptManager runat="server" id="ScriptManager1" />
<asp:UpdatePanel runat="server" id="UpdatePanel1"
UpdateMode="Conditional">
<contenttemplate>
<asp:Timer id="Timer1" runat="server"
Interval="120000"
OnTick="Timer1_Tick">
</asp:Timer>
</contenttemplate>
</asp:UpdatePanel>