How to use ASP.net Timer _ basic Application

Source: Internet
Author: User
Page code:
Copy Code code as follows:

<%@ Page language= "C #" autoeventwireup= "true" codefile= "Default.aspx.cs" inherits= "_default"%>
<%@ Register assembly= "AjaxControlToolkit" namespace= "AjaxControlToolkit" tagprefix= "CC1"%>
<! DOCTYPE HTML PUBLIC "-//w3c//dtd XHTML 1.1//en" "Http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd" >
<title>untitled page</title>
<style type= "Text/css" >
#UpdatePanel3 {
Border-right:gray 1px solid; Border-top:gray 1px solid;
Border-left:gray 1px solid; Border-bottom:gray 1px solid;
width:200px; height:200px; position:relative;
Float:left; margin-left:10px; margin-top:10px;
}
</style>
<body>
<form id= "Form1" runat= "Server" >
<asp:scriptmanager id= "ScriptManager1" runat= "Server"/>
<asp:updatepanel id= "UpdatePanel3" runat= "Server" >
<ContentTemplate>
<asp:timer id= "Timer1" runat= "Server" interval= "1000" ontick= "Timer1_Tick" >
</asp:Timer>
<asp:label id= "Label3" runat= "Server" text= "Label" ></asp:label><br/>
</ContentTemplate>
</asp:UpdatePanel>
<asp:label id= "Label4" runat= "Server" text= "Label" ></asp:Label>
</form>
</body>

CS File Code:
Copy Code code as follows:

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Threading;
public partial class _default:system.web.ui.page
{
protected void Page_Load (object sender, EventArgs e)
{
Label4.text = "Initialization time:" + DateTime.Now.ToString ();
Timer1.interval = 1000;
}
protected void Timer1_Tick (object sender, EventArgs e)
{
Label3.text = "Refresh time:" + DateTime.Now.ToSt Ring ();
}
}

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.