zl程序教程

您现在的位置是:首页 >  移动开发

当前栏目

asp.netTimer的使用方法

ASP方法 使用
2023-06-13 09:14:03 时间
页面代码: 
复制代码代码如下:

<%@PageLanguage="C#"AutoEventWireup="true"CodeFile="Default.aspx.cs"Inherits="_Default"%>
<%@RegisterAssembly="AjaxControlToolkit"Namespace="AjaxControlToolkit"TagPrefix="cc1"%>
<!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.1//EN""http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<htmlxmlns="http://www.w3.org/1999/xhtml">
<headid="Head1"runat="server">
<title>UntitledPage</title>
<styletype="text/css">
#UpdatePanel3{
border-right:gray1pxsolid;border-top:gray1pxsolid;
border-left:gray1pxsolid;border-bottom:gray1pxsolid;
width:200px;height:200px;position:relative;
float:left;margin-left:10px;margin-top:10px;
}
</style>
</head>
<body>
<formid="form1"runat="server">
<asp:ScriptManagerID="ScriptManager1"runat="server"/>
<asp:UpdatePanelID="UpdatePanel3"runat="server">
<ContentTemplate>
<asp:TimerID="Timer1"runat="server"Interval="1000"OnTick="Timer1_Tick">
</asp:Timer>
<asp:LabelID="Label3"runat="server"Text="Label"></asp:Label><br/>
</ContentTemplate>
</asp:UpdatePanel>
<asp:LabelID="Label4"runat="server"Text="Label"></asp:Label>
</form>
</body>
</html>

cs文件代码:
复制代码代码如下:

usingSystem;
usingSystem.Data;
usingSystem.Configuration;
usingSystem.Web;
usingSystem.Web.Security;
usingSystem.Web.UI;
usingSystem.Web.UI.WebControls;
usingSystem.Web.UI.WebControls.WebParts;
usingSystem.Web.UI.HtmlControls;
usingSystem.Threading;
publicpartialclass_Default:System.Web.UI.Page
{
protectedvoidPage_Load(objectsender,EventArgse)
{
Label4.Text="初始化时间:"+DateTime.Now.ToString();
Timer1.Interval=1000;
}
protectedvoidTimer1_Tick(objectsender,EventArgse)
{
Label3.Text="刷新时间:"+DateTime.Now.ToString();
}
}