Want to be able to close the Modal Popup Screen when you click on it

I have a modal popup expander and a panel inside the update panel. I have a Close button that I am associating with CancelControlId. However, I would like to be able to click outside of my modal / panel to close the panel. (instead of a close button).

I tried a couple of things and click on the plugin. Nothing seems to help. Any help or advice is greatly appreciated. Thank.

<asp:Content ID="Content3" ContentPlaceHolderID="rightNavigation" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<div id="mls_title" class="MLS_Title">
    <asp:Label ID="lblTitle1" Text="Tasks" runat="server" class="MLS_titleLbl" /><br />
</div>
    <asp:UpdatePanel ID="pnlMap" runat="server">
        <ContentTemplate>
            <div>
                <asp:Button ID="btnMap" runat="server" Text="MAP" CausesValidation="false" CssClass="btnMap" />
                <ajax:ModalPopupExtender
                    ID="ModalPopupExtender1"
                    runat="server"
                    TargetControlID="btnMap"
                    PopupControlID="panel1"
                    PopupDragHandleControlID="PopupHeader"
                    Drag="true"
                    BackgroundCssClass="ModalPopupBG">
                </ajax:ModalPopupExtender>

                <asp:Panel ID="panel1" runat="server">
                    <div class="popup_large">
                        <asp:Label ID="Label7" Text="Floor Plan" runat="server" stle="float:left"></asp:Label>
                        <asp:ImageButton ID="ImageButton1" runat="server" ToolTip="No" ImageUrl="~/Images/no.png" Style="float: right; margin-right: 20px" />
                        <br />
                        <asp:ImageButton ID="img" runat="server" Height="30em" Width="45em" />
                    </div>
                </asp:Panel>

            </div>
        </ContentTemplate>
    </asp:UpdatePanel>

      

+3


source to share


4 answers


FROM#

<AjaxToolKit:ModalPopupExtender .... BackgroundCssClass="jsMpeBackground" />

      



JavaScript (using jQuery)

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

      

+3


source


Here is a link to an example that adds to the background onclick

to close the modal:

http://forums.asp.net/t/1528820.aspx



Copied key bits here for reference:

function pageLoad() { 
    var mpe = $find("MPE"); 
    mpe.add_shown(onShown); 
} 
function onShown() { 
    var background = $find("MPE")._backgroundElement; 
    background.onclick = function() { $find("MPE").hide(); } 
} 

<AjaxToolKit:ModalPopupExtender ID="mdlPopup" BehaviorID="MPE" runat="server"
    TargetControlID="btnShowPopup" PopupControlID="pnlPopup"
    CancelControlID="btnClose" BackgroundCssClass="modalBackground" /> 

      

+3


source


write a dynamically generated script that is added in my example when the modal popup expander is loaded. Note. To bind this event handler to the ModalPopupExtender.OnLoad event, you need to add a link (in the client code, you can add "OnLoad =" mpeExample_Load "to your ModalPopupExtender tag).

protected void mpeExample_Load(object sender, EventArgs e)    { 
   ScriptManager.RegisterClientScriptBlock(this, this.GetType(), 

"hideModalPopupViaClient", String.Format(@"function hideModalPopupViaClient() {
{ 
   var modalPopupBehavior = $find('{0}');                
   if (modalPopupBehavior) modalPopupBehavior.hide();}}", 
   mpeExample.ClientID), true);  

ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "pageLoad", String.Format(@"function pageLoad() {
{                
   var backgroundElement = $get('{0}_backgroundElement');                
   if (backgroundElement) $addHandler(backgroundElement, 'click', hideModalPopupViaClient);            
}}", 
mpeExample.ClientID), true);}

      

0


source


I had to do this so that I could click the actual popup without closing it, since I have functional user controls like tab sections and text boxes in the popup.

<script type="text/javascript">
    //Hide Doc Center when clicking outside

    function pageLoad(sender, args) {
        if (!args.get_isPartialLoad()) {
            $addHandler($find("MPE")._backgroundElement, "click", closePopup);
        }
    }

    function closePopup(e) {
        $find("MPE").hide();
    }

    //End
</script>

      

Now, just make sure your BehaviorID in your actual ModelPopupExtender matches the tag above. For example:

<ajaxToolkit:ModalPopupExtender ID="Popup" runat="server" PopupControlID="Container" BehaviorID="MPE" TargetControlID="fakeTargetControl" BackgroundCssClass="modalBackground" CancelControlID="btnCancel" />

      

Basically, I think this just handles the 'click' event _backgroundElement attr of the modal popup, and on that event the closePopup () function is executed.

0


source







All Articles