Modalpopupextender how to close when clicking outside the modal

Asked

Viewed 225 times

1

Working on a cool project, I’m using the ModalPopupExtender of AjaxToolKit.

I’ve identified if I can use the attributes OkControlID and CancelControlID to define which control, a Button for example, close the modal.

<cc1:ModalPopupExtender ID="ModalPopupExtender1" 
     runat="server"
     OkControlID="btnOkay"
     CancelControlID="btnCancel">
</cc1:ModalPopupExtender>

What I would like to know is whether there is a possibility to close Modal by clicking outside the area of the Modal window that has been opened.

Is there an attribute or other code that allows you to do this?

  • Ricardo, if I’m not mistaken this library has been discontinued. I wouldn’t recommend its use, by own experience use Jquery!

  • True, but since it’s a legacy, I wouldn’t want to change much or replace code, just make an improvement

  • 1

    Here’s a reply I think it might be just what you need.

  • 1

    @Marconi interesting, I’m going to do a test

1 answer

1


Following @Marconi’s link, the English OS link solution: https://stackoverflow.com/questions/14650345/want-to-be-able-to-close-a-modal-popup-when-clicked-outside-of-it

The proposed solution is to add a Listener for the event click of background that the modal displays, and in this case close hide the modal:

  1. Set the class name of the background:

  2. With jQuery, uses the event click:

jQuery('.jsMpeBackground').click(function () { var id = jQuery(this).attr('id').replace('_backgroundElement', ''); $find(id).hide(); });

I chose to change the line that hides the modal. That’s because I want the callback function of when the modal is closed to run, so I changed that line:

$find(id).hide();

for that:

$('#btnOkay').click();

Browser other questions tagged

You are not signed in. Login or sign up in order to post.