Pausing an asp:Timer

I found a very useful blog post which described how to do it.

Here is my take on it…

function IsTimerEnabled()
{
    var timer = $find("timer");
    return timer.get_enabled();
}

function PauseTimer()
{
    var timer = $find("timer");
    timer.set_enabled(false);
    timer._stopTimer();
    window.status = "Timer paused";
    window.setTimeout("window.status = ''", 1000);
}

function ResumeTimer()
{
    if (wasTimerEnabled)
    {
        var timer = $find("timer");
        timer.set_enabled(true);
        timer._startTimer();
        window.status = "Timer resumed";
        window.setTimeout("window.status = ''", 1000);
    }
}

var wasTimerEnabled = false;

function OnOpenSomeDialog()
{
    wasTimerEnabled = IsTimerEnabled();
    if (wasTimerEnabled)
    {
        PauseTimer();
    }
}

function OnSomeDialogClosed()
{
    ResumeTimer();
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s