我有一个网页表单,我希望为用户显示时间标签,如180秒, 我已经完成了以下代码,
<div>
<asp:ScriptManager ID="SM1" runat="server"></asp:ScriptManager>
<asp:Timer ID="timer1" runat="server" Interval="1000"
OnTick="timer1_tick">
</asp:Timer>
</div>
<div>
<asp:UpdatePanel ID="updPnl" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Label ID="lblTimer" runat="server"></asp:Label>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="timer1" EventName="tick" />
</Triggers>
</asp:UpdatePanel>
</div>
和背后的代码
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
Page.Header.Title = "Test";
}
if (!SM1.IsInAsyncPostBack)
Session["TimeCount"] = DateTime.Now.AddSeconds(180).ToString();
}
和
protected void timer1_tick(object sender, EventArgs e)
{
if (0 > DateTime.Compare(DateTime.Now,
DateTime.Parse(Session["TimeCount"].ToString())))
{
lblTimer.Text = "Number of Second Left: " +
((Int32)DateTime.Parse(Session["TimeCount"].
ToString()).Subtract(DateTime.Now).TotalSeconds).ToString();
}
else
{
}
}
我面临的问题是每次用户点击页面计数器中的按钮再次刷新到180,其次这个显示修复值如177,170,我想显示标签自动减少?