ASP.NET Timer控件实现倒计时功能,如何让计时结束自动交卷

protected void Timer1_Tick(object sender, EventArgs e)
{
int hour;
int minute;
int second;
int examTime = 20;
if (Session["examtime"] != null)
{
examTime = Convert.ToInt32(Session["examtime"]);

}

// 如果还有剩余时间,就显示剩余的分钟和秒数
if (examTime > 0)
{
examTime--;
Session["examtime"] = examTime;
hour = examTime / 3600;
minute = (examTime - hour * 3600) / 60;
second = examTime % 60;
lblTimer.Text = string.Format("{0:00}:{1:00}:{2:00}", hour, minute, second);

}

}

把你的int examTime = 20;定义在timer tick函数外,不然每次执行就相当于重新定义一次,就永远都是20了。

在timer tick里面直接写。
if(examTime==0)
{
...............

}
温馨提示:内容为网友见解,仅供参考
无其他回答
相似回答