停止和重新启动ASP.NET定时器 [英] Stop and Restart ASP.NET Timer

查看:1168
本文介绍了停止和重新启动ASP.NET定时器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我的网页上的ASP.NET Timer控件。

I have an ASP.NET Timer control on my web page.

定时器用作一个的UpdatePanel 触发。一旦此面板的内容加载,我使用禁用定时器 Timer.Enabled = FALSE;在code 。这从触发Tick事件禁用定时器。

The timer is used as a trigger for an UpdatePanel. Once the content of this panel is loaded, I disable the Timer using Timer.Enabled = false; in the code. This disables the Timer from firing the Tick event.

我想如果用户希望重新运行按钮上点击code重新启动该定时器。不过,如果我使用 Timer.Enabled = TRUE; 在按钮单击事件,它不仅使定时器当页面postsback。显然,这不是我希望的行为。

I want to restart this timer if the user wishes to re-run the code on a button click. However, if I use Timer.Enabled = true; in the button click event, it only enables the timer when the page postsback. Evidently, this is not the behaviour I would like.

我试着做了使用JavaScript一样,

I tried to do the same using javascript,

var timer = $find('<%=TimerAH.ClientID %>');
timer._startTimer();
//timer.set_enabled(true);

这code也于事无补。我将不胜感激,如果有人可以帮我解决这个问题。谢谢你。

This code also does not help. I would be grateful if someone could help me solve this issue. Thanks.

推荐答案

您有ASP.NET定时器,你可以很容易地使用这些众多的客户端站点的功能。

You have these many client site functions for ASP.NET timer that you can easily use.

但要小心的Javascript功能,下手的下划线私人fucnctions按照惯例即可。他们可以由作者来改变,但我想它的安全,因为微软使用被知道是好提供向后兼容性。

But be careful that Javascript function which start with underscore are private fucnctions by convention. They can be changed by the author, but i guess its safe to use as Microsoft is know to be good in providing backward compatibility.

<一个href=\"http://disturbedbuddha.word$p$pss.com/2007/11/26/controlling-the-aspnet-timer-control-with-javascript/\"相对=nofollow>用JavaScript 控制ASP.NET定时器控制

Controlling the ASP.NET Timer Control with JavaScript

    var timer = $find(‘<%= Timer1.ClientID %>’);

    //returns the timer’s interval in milliseconds: 
    var waitTime = timer.get_interval;       

    //sets the timer’s interval to 5000 milliseconds (or 5 seconds): 
    timer.set_interval(5000);       

    //returns whether or not the timer is enabled: 
    var isTimerEnabled = timer.get_enabled();       

    //disables the timer: 
    timer.set_enabled(false);       

    //starts the timer: 
    timer._startTimer();       

    //stops the timer: 
    timer._stopTimer();

这篇关于停止和重新启动ASP.NET定时器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆