Search code examples
javascriptjquerymodalpopupextender

Run javascript when modalpopupextender is shown


This questions was already answered here - How to specify javascript to run when ModalPopupExtender is shown - but the accepted solution is not working for me.

The modalpopupextender is declared as below:

<ajaxtoolkit:ModalPopupExtender ID="mpe" runat="server" TargetControlID="btn"
        PopupControlID="pnlModal" PopupDragHandleControlID="pnlModalDragHandle"   BackgroundCssClass="modalBackground"
    CancelControlID="btnModal" DropShadow="true"/> 

The showing / hiding works fine. What does not work is linking a client script to the showing event of the modal popup extender. Based on the original question, I tried:

 <script type="text/javascript">
    function pageLoad() {
    var popup = $find('mpe');
    popup.add_shown(SetShowing);
    }

function SetShowing() {
    alert('showing');
  }

 </script>

Nothing happened. No alert, no errors. Reading further in the original post, I even added this line in the script: Sys.Application.add_load(pageLoad);

The additional line had no effect. Any ideas why the original answer is not working? Thanks, I have been trying for hours.


Solution

  • I ended up having to attack this problem another way. None of the suggestions were able to successfully detect when the modalpopupextender was displayed. I instead changed my approach to handle user actions on the shown elements - like focusing on a textbox, etc. I could be confident the modalpopupextender was displayed if the user was interacting with it.

    If you came here, I would direct you to the original post here - How to specify javascript to run when ModalPopupExtender is shown - and hope you were more successful than I was.

    Thank you to everyone who commented, I sincerely appreciate your time.