加载页面后,我的倒数计时器开始计时。但是我想要的是计时器应该在单击按钮后启动。
protected void Timer1_Tick(object sender, EventArgs e)
{
if (TimeAllSecondes > 0)
{
TimeAllSecondes = TimeAllSecondes - 1;
}
TimeSpan time_Span = TimeSpan.FromSeconds(TimeAllSecondes);
hh = time_Span.Hours;
mm = time_Span.Minutes;
ss = time_Span.Seconds;
Label2.Text = " " + hh + ":" + mm + ":" + ss;
}
protected void Button1_Click(object sender, EventArgs e)
{
}
在设计时禁用计时器控件,例如:
runat="server" Interval="2000" Enabled="False" />
然后在Button_Click中启用它:
protected void Button1_Click(object sender, EventArgs e)
{
Timer1.Enabled = true;
}
除非在服务器端计时(避免来自客户端的操作)很重要,否则最好在Javascript中执行此操作。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句