2
我的应用程序中有一个要求显示日期和时间。 我在我的.net应用程序中使用Ajax来执行此操作。在ASP.net中显示当前时间并让它打勾
目前我有这样的代码
<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
谢谢!
你想显示服务器时间或客户端的时间? (如果后者使用javascript only解决方案将是更好的选择) – Oded 2012-07-24 19:50:46
或者,在返回的HTML中显示服务器的时间,但使用Javascript将该时间与本地机器进行比较,然后根据本地时钟每秒更新一次,所以它将显示服务器的时间而不需要轮询它。 – Dai 2012-07-24 19:52:36
好问题。这真的没关系,因为这将在公司的Intranet上使用。我不确定...我猜客户可能是最好的... – envinyater 2012-07-24 19:55:06