The realization method of timer without refreshing timer in asp.net _ Practical skills

Source: Internet
Author: User

In this paper, the implementation method of timer without flush timer in asp.net is described. The timer control has to be implemented without refreshing, using AJAX technology, which uses VS2008 's own Ajax technology.

The first step is to add a ScriptManager control, and then add a UpdatePanel to hold the contents of the Timer control to achieve no refresh. Here is the detailed content:

First, the foreground code is as follows:

<form id= "Form1" runat= "Server" >
  <asp:scriptmanager id= "ScriptManager1" runat= "Server" >
  </ asp:scriptmanager>
      <asp:updatepanel id= "UpdatePanel1" runat= "Server" >
      <ContentTemplate>
        <asp:timer id= "Timer1" runat= "Server" interval= "60000" ontick= "Timer1_Tick" >
        </asp:Timer>
      </ContentTemplate>
      </asp:UpdatePanel>
</form>

Remember ScriptManager must be placed in the <form> tag, can be placed anywhere. When you add a UpdatePanel control, you use a very important property contenttemplate, or you cannot achieve a no refresh effect. Here we set the 6 second timer to trigger the event once.

Second, the background code is as follows:

protected void Page_Load (object sender, EventArgs e)
{}
protected void Timer1_Tick (object sender, EventArgs e) c3/>{
//Here you can manipulate the things you want to do, such as a timed query database
scriptmanager.registerstartupscript (this, this.) GetType (), "", "alert (' Hello ');", true);
}

It is hoped that the examples described in this paper will help us asp.net program design.

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.