Wednesday, March 21, 2012

ModalPopup add_hidden event

I am trying to hook the hidden event of the ModalPopup. I am getting it work sporadically. It seems that there is a timing issue when the javascript runs.

If I wrap up the add_pageLoaded in a setTimeout it works, actually it only works after I refresh the page. How/When can I hook this event. Below is what I have so far.

Specifically, pop is null. The find is not locating my modal popup properly.

<script language='javascript'>Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(AMModalPopupPageLoaded);function AMModalPopupPageLoaded(sender, args){ var pop = $find('<%= ModalPopup1.ClientID%>_ajaxModalPopup'); if (pop != null) pop.add_hidden(function(){alert('hidden');}); else alert ('nope'); Sys.WebForms.PageRequestManager.getInstance().remove_pageLoaded(AMModalPopupPageLoaded);}</script>
You could specify a BehaviorID on the extender and retrieve it using that.

That sounds good, however, i don't know how to do thatHuh? Can you provide me a sample or the location of the documentation?

thanks!


Ok, I simply changed:
Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(AMModalPopupPageLoaded)
To:
Sys.Application.add_load(AMModalPopupPageLoaded);
And everything works perfectly!

No comments:

Post a Comment