Saturday, March 24, 2012

Invoke ModalPopupExtenders .Show() method within javascript code

Hi,

A colleague wrote an extender to validate an address (street name & postal code). He uses a web service for that BUT he didn't write the necessary code in the _onMethodFailed method !

In this method I woud like to display a popup containing 'yes' and 'no' buttons (to ask the customer if he wants to keep the wrong values or no).

Currently, I have an asp:panel with a ModalPopupExtender (which ID is 'AddressErrorPopup') linked on it.

So, in the address validation extender I would like to do something like that :

_onMethodFailed: function(err, response, context) { if (this._popupValue) { var popupExtender = $get(this._popupValue); if (popupExtender) popupExtender.Show(); }}


the _popupValue variable contains 'AddressErrorPopup' : the ID of the ModalPopupExtender.

Problem : the $get(this._popupValue) returns null...

Is there a way to invoke the Show() method of a ModalPopupExtender in the javascript code of an other extender on the same form ?

Thx for your answer...

You need to use $find instead of $get to locate ajax controls. $get is for DOM elements.

Also, make sure that the modalpopup has BehaviorID="AddressErrorPopup" as the actual client ID may be different depending on the naming container hierarchy. Store the BehaviorID in the _popupValue property and then you should find the popup OK regardless of the naming container.


Ok !

Thank you for your help, this is exactly what I needed.

I'm not good at javascript/ajax, sorry for thatConfused


No need to be sorry...that's an easy mistake to make. Working with the ajax toolkit, you will become good at javascriptSmile

No comments:

Post a Comment