我的申请中要求显示日期和时间。我在我的 .net 应用程序中使用 Ajax 来执行此操作。
目前我有这个代码
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<asp:Timer ID="UpdateTimer" runat="server" Interval="1000" OnTick="UpdateTimer_Tick" />
<asp:UpdatePanel ID="TimedPanel" runat="server" UpdateMode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="UpdateTimer" EventName="Tick" />
</Triggers>
<ContentTemplate>
<asp:Label runat="server" ID="DateStampLabel" />
</ContentTemplate>
</asp:UpdatePanel>
刷新页面时除了延迟一秒外,它工作得很好。我的问题是,这是实现这一目标的最佳方法吗?我也许可以不显示秒数而侥幸……这可能不太重要。如果我这样做,我该怎么做?
这是代码隐藏...
Protected Sub UpdateTimer_Tick(ByVal sender As Object, ByVal e As System.EventArgs)
DateStampLabel.Text = DateTime.Now.ToString()
End Sub
谢谢!