关于Timer 定时器的使用问题.请教高手,急.!!!
我在添加好Timer控件后,进行了初始化的参数设置,<asp:Timer ID="tm" runat="server" Interval="5000" Enabled="true" EnableViewState="true" OnTick="tm_Tick" >
然后在.cs文件中写入如下代码:
protected void Page_Load(object sender, EventArgs e)
{
this.Label1.Text = "";
}
protected void tm_Tick(object sender, EventArgs e)
{
this.Label1.Text = "2gff";
}
怎么这个定时器就不起作用啊 ?
请教高手,最好能详细点..
------解决方案--------------------
前端:
<form id="form1" runat="server">
<div>
<asp:TextBox ID="txtName" runat ="server" ></asp:TextBox>
<asp:Button ID="btnAdd" runat ="server" Text ="添加" OnClick ="Add_Res" />
</div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:Timer ID="Timer1" runat="server" Enabled ="true" Interval ="50" OnTick ="T_Tick">
</asp:Timer>
</form>
后端:
protected void T_Tick(object sender, EventArgs e)
{
btnAdd.Enabled = false;
btnAdd.Text = "Enable";
}
我的运行很正常
------解决方案--------------------
前台代码:
HTML code
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!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 runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<div>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<asp:Timer ID="Timer1" runat="server" Interval="6000" OnTick="Timer1_Tick">
</asp:Timer>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>
</body>
</html>