欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

asp.net Timer的使用方法

程序员文章站 2022-07-06 17:52:54
页面代码: 复制代码 代码如下:<%@ page language="c#" autoeventwireup="true" codefile="defaul...
页面代码: 
复制代码 代码如下:

<%@ 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">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="head1" runat="server">
<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>
</head>
<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>
</html>

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

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 = "初始化时间:" + datetime.now.tostring();
timer1.interval = 1000;
}
protected void timer1_tick(object sender, eventargs e)
{
label3.text = "刷新时间:" + datetime.now.tostring();
}
}