如何在asp.net C#中单击按钮后启动倒计时?
我加载页面后,倒计时开始。但我想要的是,定时器应该在点击按钮后启动如何在asp.net C#中单击按钮后启动倒计时?,c#,asp.net,timer,C#,Asp.net,Timer,我加载页面后,倒计时开始。但我想要的是,定时器应该在点击按钮后启动 protected void Timer1_Tick(object sender, EventArgs e) { if (TimeAllSecondes > 0) { TimeAllSecondes = TimeAllSecondes - 1; } TimeSpan time_Span = TimeSpan.FromSecon
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" />
然后在按钮中启用它,单击:
protected void Button1_Click(object sender, EventArgs e)
{
Timer1.Enabled = true;
}
在Javascript中这样做会更好,除非服务器端定时(避免客户端操作)很重要。如何在页面加载中启动它?您是如何在web应用程序中使用计时器的?很高兴听到,您能勾选此答案左侧的“全息”复选框吗?它会给您几分,并让每个人都知道您的问题已解决。@JeremyThompson当我使用此选项时,则“计时器”不起作用。请help@ManishJain-您是否阅读了,或,或,甚至提供了错误?来吧,你已经在这里呆了很长时间了,不会随便告诉别人“它不起作用”——WOMM——新的question@JeremyThompson我没有告诉你我有任何错误或者你的解决方案不起作用。我刚才告诉过你,启用后点击里面的按钮;计时器刻度中的断点未出现。