<asp:Timer ID="timer1" runat="server" OnTick="timer1_tick"> </asp:Timer>
<asp:UpdatePanel ID="updatepanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Label ID="lbltimer" runat="server"></asp:Label>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="timer1" EventName="tick" />
</Triggers>
</asp:UpdatePanel>
在页面加载中进行编码!IsPostback
timer1.Enabled = true;
Session["timeout"] = DateTime.Now.AddMinutes(60).ToString();
这是tick事件编码。问题是每当我运行应用程序时,tick事件都不会触发。该应用程序是Asp.net应用程序。
protected void timer1_tick(object sender, EventArgs e)
{
if (0 > DateTime.Compare(DateTime.Now,
DateTime.Parse(Session["timeout"].ToString())))
{
int hrs = (((Int32)DateTime.Parse(Session["timeout"].
ToString()).Subtract(DateTime.Now).TotalMinutes)) / 60;
int mins = (((Int32)DateTime.Parse(Session["timeout"].
ToString()).Subtract(DateTime.Now).TotalMinutes)) % 60;
int seconds = (((Int32)DateTime.Parse(Session["timeout"].
ToString()).Subtract(DateTime.Now).TotalSeconds)) % 60;
lbltimer.Text = "Time left is " + hrs.ToString() + " : " + mins.ToString() + " : " + seconds.ToString();
if (mins == 1 && seconds == 0 && hrs == 0)
{
lbltimer.Text = "Please submit test 1min left";
}
else if (hrs == 0 && mins == 0 && seconds == 0)
{
lbltimer.Text = "Test Time Over";
}
}
}
答案 0 :(得分:0)
在此代码行中,添加计时器间隔。我没有看到间隔被设置在哪里。
<asp:Timer ID="timer1" runat="server" OnTick="timer1_tick" Interval="your_interval_in_ms">