asp.net+ajax倒计时问题
一朵-奇葩 2011-09-30 04:17:53 这段时间在做一个考务系统,但在学生考试页面的倒计时遇到了点问题,在考试时间结束的时候不能自动交卷,要随意点击一个按钮才会交卷,我要的效果是不用点击,时间到了自动交卷,不知道怎么解决,希望大家帮帮忙!急用!!!下面是代码:
后台代码:
public static int timenull; //总时间
public static int sheng; //剩余时间
//倒计时
protected void Timer1_Tick(object sender, EventArgs e)
{
int minute; //当前分钟
int second=0; //秒
DateTime dt = PExBLL.NewTime(); //获取服务器时间
DateTime sf = ENDTIME;
if (dt < sf)
{
TimeSpan ts = dt.Subtract(sf).Duration(); //当前考试的总时间
timenull = ts.Days * 24 * 60 * 60 + ts.Hours * 60 * 60 + ts.Minutes * 60 + ts.Seconds; //把当前考试的总时间转换为秒
if (timenull > 0)
{
timenull--;
minute = timenull / 60;
second = timenull % 60;
lblTime.Text = string.Format("{0:00}分钟{1:00}秒", minute, second);
}
}
else
{
ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), " ", "alert('考试时间已到,系统将自动提交试卷')", true); //给出提示
Result(); //强行交卷
}
}
//倒计时
protected void Timer1_Load(object sender, EventArgs e)
{
int minute; //当前分钟
int second; //秒
DateTime dt = PExBLL.NewTime(); //获取服务器时间
DateTime sf = ENDTIME;
if (dt < sf)
{
TimeSpan ts = dt.Subtract(sf).Duration(); //当前考试的总时间
timenull = ts.Days * 24 * 60 * 60 + ts.Hours * 60 * 60 + ts.Minutes * 60 + ts.Seconds; //把当前考试的总时间转换为秒
if (timenull > 0)
{
minute = timenull / 60;
second = timenull % 60;
lblTime.Text = string.Format("{0:00}分钟{1:00}秒", minute, second);
}
}
else
{
ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), " ", "alert('考试时间已到,系统将自动提交试卷')", true); //给出提示
Result(); //强行交卷
}
}