Default.aspx页面:先放一个ScriptManager控件到页面,然后拉一个UpdatePanel控件。UpdatePanel里面放一个Label用于显示时间,放一个timer控件用于控制时间的更新。最后,timer控件的Interval属性设置为1000,让它每1秒执行一次即更新时间。
.aspx页面的源码:
<div style="background-color: inherit;" class="auto-style1">
<asp:ScriptManager ID="smtime" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
Time:
<asp:Label ID="Lbtime" runat="server" ForeColor="#66CCFF"></asp:Label>
<asp:Timer ID="Tmtime" runat="server" Interval="1000">
</asp:Timer>
</ContentTemplate>
</asp:UpdatePanel>
</div>
.cs页面代码
protected void Page_Load(object sender, EventArgs e)
{
Lbtime.Text = DateTime.Now.ToString("F");
}