【发布时间】:2010-09-11 15:57:14
【问题描述】:
您能推荐我一种在 ASP.NET 页面上放置倒数计时器的方法吗?
现在我使用这个代码:
Default.aspx
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Label ID="Label1" runat="server">60</asp:Label>
<asp:Timer ID="Timer1" runat="server" Interval="1000"
ontick="Timer1_Tick">
</asp:Timer>
</ContentTemplate>
</asp:UpdatePanel>
Default.aspx.cs
protected void Timer1_Tick(object sender, EventArgs e)
{
int seconds = int.Parse(Label1.Text);
if (seconds > 0)
Label1.Text = (seconds - 1).ToString();
else
Timer1.Enabled = false;
}
但它的流量昂贵。我更喜欢纯客户端方法。在 ASP.NET 中可能吗?
【问题讨论】:
-
你问这个很有趣......我几天前刚刚实施了一个类似于你的解决方案。它必须完成,这是快速而肮脏的。我很想看看如何在客户端做这个。
标签: asp.net javascript asp.net-ajax