各位前辈好,我之前一直做C# - WinForm编程的,最近才开始接触ASP.NET,所以有些东西十分不解,希望大家能给予指导。我的Default2.aspx是这么写的:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs"
Inherits="Default2" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html >
<head id="Head1" runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering=true >
</asp:ScriptManager>
<div>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Label ID="Label1" runat="server" Text="This is a label!">
</asp:Label>
<asp:Timer ID="Timer1" runat="server" Interval=100 ontick="Timer1_Tick">
</asp:Timer>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>
</body>
</html>
然后我给Timer写了更新label1文字的代码:using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;public partial class Default2 : System.Web.UI.Page
{
public int tTimer = 0;
protected void Page_Load(object sender, EventArgs e)
{ }
protected void Timer1_Tick(object sender, EventArgs e)
{
Label1.Text = tTimer++.ToString();
}
}
的确是无刷新瞬间更新了,但是为什么不能第二次,第三次这样无限刷新下去?难道Timer达到指定时间后会让enable处于false的状态么?这里我十分不解,麻烦各位前辈能给说说原理和注意事项……谢谢!
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs"
Inherits="Default2" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html >
<head id="Head1" runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering=true >
</asp:ScriptManager>
<div>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Label ID="Label1" runat="server" Text="This is a label!">
</asp:Label>
<asp:Timer ID="Timer1" runat="server" Interval=100 ontick="Timer1_Tick">
</asp:Timer>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>
</body>
</html>
然后我给Timer写了更新label1文字的代码:using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;public partial class Default2 : System.Web.UI.Page
{
public int tTimer = 0;
protected void Page_Load(object sender, EventArgs e)
{ }
protected void Timer1_Tick(object sender, EventArgs e)
{
Label1.Text = tTimer++.ToString();
}
}
的确是无刷新瞬间更新了,但是为什么不能第二次,第三次这样无限刷新下去?难道Timer达到指定时间后会让enable处于false的状态么?这里我十分不解,麻烦各位前辈能给说说原理和注意事项……谢谢!
解决方案 »
- 后台如何使用iframe
- 请教大家一个asp.net网站出错的问题
- 问题的关键是,我不是J2EE专家!!!
- GridView中类似于dataGrid的VirtualItemCount的属性是什么?
- ModalDialog有没有办法自动关闭,并刷新父页面?
- 锚点问题,用到iframe,混在一起了,js高手进来看下
- 关于datagrid反向显示的问题(在线等)
- mssccprj.scc说是个Source Code Control file,怎么用,怎么打开工程的时候说找不到该文件但是明明有的!??
- 网站开发
- 哪位朋友给偶讲讲在ASP.NET中使用TREEVIEW的具体过程.
- DataGrid列控制的问题?请各位进来帮忙
- Asp.net 控件ClientID,UniqueID命名规则问题
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering=true >
</asp:ScriptManager>
<div>
<asp:Timer ID="Timer1" runat="server" Interval=100 ontick="Timer1_Tick">
</asp:Timer>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Label ID="Label1" runat="server" Text="This is a label!">
</asp:Label>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
ViewState["tTimer"]="0";
}
} protected void Timer1_Tick(object sender, EventArgs e)
{
ViewState["tTimer"] = (Convert.ToInt32(ViewState["tTimer"]) + 1).ToString();
Label1.Text = ViewState["tTimer"].ToString(); }你public int tTimer = 0;这样设置,每次页面回发都清0了!!
改成ViewState["tTimer"]即可!!