Wednesday, March 21, 2012

Question on Modalpopupextender & according events

I'm using a modalpopupextender in a user control, which sits on a basepage of my website.
TargetControlID, PopupControlID & CancelControlID are all set and everything works great & smooth.

However I'd like to implement some custom code on the button click events.
What I want to do:

On my masterpage, there is an ajax timer control which is handling the automatic refresh of the basepage content.
The user control with the modalpopupextender is used on one of the basepages. Users can pop-up a screen with this to do selections in.
However, the ajax timer control will still be handling the refresh and it will cause the modal popup to close again during a refresh.

The way I thought to handle this is to stop the ajax timer control on the masterpage when a user clicks the button to show the modalpop-up
and start the timer again when the user clicks the cancel or ok button of the modalpopup.
I think you can't do this directly as the button controls that trigger the modalpopup events cannot be assigned to do anything else.
I tried the trick with the hidden control and the code-behind stuff to stop & start the timer, but I find it somehow slow and also get some weird effects with other controls on the basepage.

I know it's also possible to stop & start an ajax timer client side with the code shown here:http://forums.asp.net/t/1094798.aspx
but I was wondering how to implement it (I'm an Ajax n00b) and if this is the way to go or to stay away from to solve my little problem.

Any help is greatly appreciated!
Thanks!

I fixed it. For anyone who needs this, the problem was with the prefix that needs to be added to the timercontrol name, because it sits on the masterpage and
the function that stops & starts the timer is called from the basepage.

What I basically did:

//We define clientside scripts to stop & start the ajax refresh timer
//from clientside! We do this because the popupmodalextender
//binds to the linkbuttons lnkbtnHistory & lnkbtnCancel but will not handle server side code
//without using hidden 'in-between' controls
//note that the javascript looks for the control "ctl00_tmrRefresh".
//the 'ct100_' prefix is needed because the control resides on the masterpage!

Page.ClientScript.RegisterClientScriptBlock(this.GetType(),"stopTimer", @."function stopTimer() {var timer=$find('ctl00_tmrRefresh');timer._stopTimer(); }",true);
Page.ClientScript.RegisterClientScriptBlock(this.GetType(),"startTimer", @."function startTimer() {var timer=$find('ctl00_tmrRefresh');timer._startTimer(); }",true);

//add custom attributes that refer to the registered client scripts
//with client-side code to stop & start the refresh the timer on button click event

lnkbtnHistory.Attributes.Add("onclick","stopTimer()");
lnkbtnCancel.Attributes.Add("onclick","startTimer()");

No comments:

Post a Comment