如何停止Ajax Timer Control [英] How to stop Ajax Timer Control
问题描述
我正在使用Ajax计时器控件进行在线测试我正在使用Timer1.Enabled = true;用于启动计时器控制之后,它在超时之后继续下面的功能我希望java脚本消息显示测试超时消息,但是java脚本消息不起作用
< pre lang =cs> protected void Timer1_Tick( object sender,EventArgs e)
{
if (会话[ time] == null )
{
Session [ time] = DateTime.Now;
}
dt2 = Convert.ToDateTime(会话[ time]) ;
TimeSpan ts1;
ts1 = dt2.Subtract(DateTime.Now);
lbltimer.Text = ts1.Hours.ToString()+ : + ts1。 Minutes.ToString()+ : + ts1.Seconds.ToString();
if (DateTime.Now > = dt2)
{
// RadioButtonList1.Enabled = false;
lbltimer.Text = 超时;
}
}
你必须使用Ajax< asp:updatepanel>
控制。
并将您的标签放入其中。
请检查以下内容作为指南
http://www.c-sharpcorner.com/UploadFile/364074/timercontrol-with-updatepanel-in-ajax-using-Asp-Net/ [ ^ ]
有很多方法可以停止计时器:
1。
void timer1_elapse(无论是obj,无论args)
{
response.write( 已经10秒,现在开火);
timer1.stop(); // 将停止计时器,因此不会每10秒执行一次。
}
2。
timer1.Enabled = false ; // 禁用/停止计时器
timer1.Enabled = 真跨度>; // 启用计时器
你可以还有一个javasctipt功能。请参阅此处:
function stopTimer()
{
var timer =
find( <%= ajaxTimer.ClientID%>)
timer._stopTimer();
}
--Amit
I am using Ajax timer control for online test i am using " Timer1.Enabled = true;" for starting timer control after that its going on below function after time out i want java script message to display test time out message , but java script message is not working
protected void Timer1_Tick(object sender, EventArgs e)
{
if (Session["time"] == null)
{
Session["time"] = DateTime.Now;
}
dt2 = Convert.ToDateTime(Session["time"]);
TimeSpan ts1;
ts1 = dt2.Subtract(DateTime.Now);
lbltimer.Text = ts1.Hours.ToString() + ":" + ts1.Minutes.ToString() + ":" + ts1.Seconds.ToString();
if (DateTime.Now >= dt2)
{
//RadioButtonList1.Enabled = false;
lbltimer.Text = "Time Out";
}
}
you have to use the Ajax<asp:updatepanel>
control.
and put your label inside that.
please check the following as a guide
http://www.c-sharpcorner.com/UploadFile/364074/timercontrol-with-updatepanel-in-ajax-using-Asp-Net/[^]
There is many ways to stop the timer:
1.
void timer1_elapse(whatever obj, whatever args) { response.write("It has been 10 seconds, firing now"); timer1.stop(); // will stop the timer, so it will not execute every 10 seconds. }
2.
timer1.Enabled = false; //Disables/Stops the timers timer1.Enabled = true; //Enables the timers
You can also go for a javasctipt function. See here:
function stopTimer() { var timer =
find("<%=ajaxTimer.ClientID%>") timer._stopTimer(); }
--Amit
这篇关于如何停止Ajax Timer Control的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!