asp.net AJAX Timer Control overview

Source: Internet
Author: User
Tags time interval

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>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.