计时器时钟周期事件未触发
本文关键字:事件 时钟周期 计时器 | 更新日期: 2023-09-27 18:36:25
<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>
在页面加载中编码!回发
timer1.Enabled = true;
Session["timeout"] = DateTime.Now.AddMinutes(60).ToString();
这是即时报价事件编码。问题是每当我运行应用程序时,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";
}
}
}
在代码的这一行中,添加计时器间隔。我没有看到在任何地方设置间隔。
<asp:Timer ID="timer1" runat="server" OnTick="timer1_tick" Interval="your_interval_in_ms">