<asp:UpdatePanel ID=”UpdatePanel” runat=”server” UpdateMode=”Conditional”>
<ContentTemplate>
<asp:Timer ID=”Timer1″ runat=”server” Interval=”1000″ OnTick=”Timer1_Tick”></asp:Timer>
<asp:Label ID=”Label1″ runat=”server” Text=”Label”></asp:Label>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID=”Timer1″ EventName=”Tick” />
</Triggers>
</asp:UpdatePanel>
protected void Page_Load(object sender, EventArgs e)
{
Label1.Text = DateTime.Now.ToString(“yyyy/MM/dd HH:mm:ss”);
}
protected void Timer1_Tick(object sender, EventArgs e)
{
Label1.Text = DateTime.Now.ToString(“yyyy/MM/dd HH:mm:ss”);
}
<ContentTemplate>
<asp:Timer ID=”Timer1″ runat=”server” Interval=”1000″ OnTick=”Timer1_Tick”></asp:Timer>
<asp:Label ID=”Label1″ runat=”server” Text=”Label”></asp:Label>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID=”Timer1″ EventName=”Tick” />
</Triggers>
</asp:UpdatePanel>
protected void Page_Load(object sender, EventArgs e)
{
Label1.Text = DateTime.Now.ToString(“yyyy/MM/dd HH:mm:ss”);
}
protected void Timer1_Tick(object sender, EventArgs e)
{
Label1.Text = DateTime.Now.ToString(“yyyy/MM/dd HH:mm:ss”);
}
解决方案
40
你可以测试(例如)这样的代码
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title></title> </head> <body> <form id="form1" runat="server"> <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager> <asp:UpdatePanel ID="UpdatePanel" runat="server" UpdateMode="Conditional"> <ContentTemplate> <asp:Timer ID="Timer1" runat="server" Interval="1000" OnTick="Timer1_Tick"></asp:Timer> <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label> </ContentTemplate> </asp:UpdatePanel> <asp:Label ID="Label2" runat="server" Text="Label"></asp:Label> </form> <asp:Label ID="Label3" runat="server" Text="Label"></asp:Label> </body> </html>
using System; public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { Label1.Text = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"); Label2.Text = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"); Label3.Text = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"); } protected void Timer1_Tick(object sender, EventArgs e) { Label1.Text = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"); } }