单击ASP.NET中的按钮后,如何开始倒计时? [英] How can I start count down timer after clicking a button in ASP.NET?
本文介绍了单击ASP.NET中的按钮后,如何开始倒计时?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想点击提交按钮而不是页面加载时启动倒计时器
I want to start the count down timer after I click on the submit button instead of when the page is loaded
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)
{
}
我的尝试:
我尝试在Button1_Click方法中调用Timer1_Tick方法作为Timer1_Tick(发送方,e),但它不起作用。
What I have tried:
I have tried calling the Timer1_Tick method as Timer1_Tick(sender, e) within the Button1_Click method , but it didn't work.
推荐答案
试试这个
try this
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack) {
Timer1.Enabled = false;
}
}
protected void Button1_Click(object sender, EventArgs e)
{
Timer1.Enabled = true;
}
这篇关于单击ASP.NET中的按钮后,如何开始倒计时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文