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();
}
}
复制代码 代码如下:
<%@ 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();
}
}
上一篇: 微信小程序文章详情功能完整实例
下一篇: es6函数name属性功能与用法实例分析