Tuesday, July 3, 2012

Using ASP.NET AJAX Timer Control and ASP.NET AJAX ModalPopup Dialog

Have you ever used ASP.NET AJAX and Timer Control and ModalPopup Ctonrol on a page?
If yes, Then how you Managed to Display Modalpopup when Timer Control Tick event occurs?

Many of you have faced such situation even i have faced the same.
But i used a very simple solution to handle the same.

What is did it is, Stopped the timer control when i view the ModalDialog and then restart the timer when Modal Pup is closed.

You will ask what is the trick in this.
The answer raises another question. How to handle timer control when you have set Modalpop okControlID and CancelControlID.
Because clicking this control does not raise any server event but it is handle at client side.

In order to achive you have handle timer control at client side instead on Code behind

To achieve the same add OkScript, If you just have one button to Close the Modal Popup Control and you have using through OKControlID.
In that Write below code

okscript="okTimerscript();"


function okTimerscript()
{
    var timer = $find('<%= tmrControl.ClientID
    timer.set_enabled(true);   
    Timer._startTimer();
}


you would be wondering about the methods. But, forget about this all these methods will be handled by AJAX Control toolkit Timer.js file.

Enjoy and happy coding...

Thank you.