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.