Search code examples
asp.netmodality

Open aspx page as a modal popup


I have a grid with edit option ,and on edit button click i need to redirect to an edit page . the requirement is to get this edit page as a popup with background (prev page) greyed out.

i tried modal popup, but the controls are on a separate page .

i tried modal popup with panel and a Iframe : this works..but thean another problem arises.i need to close the page on 'SAVE' or 'Cancel' butotn click .these controls would be on the edit page and not on the prev page .any help is appreciated .

Thanks Rajat


Solution

  • We can open an aspx as popup using IFrame as follows,

    First take a button and provide onclick event as follows

       <input id="btnSymbol" type="button" value="..." onclick="OpenMyPopUp()" runat="server"/> 
    

    Next In the page provide a "Div" tag with id as follows

       <div id="MyDialog">
            </div>
    

    Then find below the two methods which take the present URL and opens a aspx page in a popup using IFRAME

        function OpenMyPopUp(){openPopup('OpenPage.aspx', 530, 800, 'Page Title');}
    

    The Four parameters are sent as follows URL,height,width,title

       function openPopup(url, h, w, t) {
    if (url != null && h != null && w != null && t != null) {
    
        urlBase = location.href.substring(0, location.href.lastIndexOf("/") + 1);
        url = urlBase + url;
        $('#MyDialog').html('<iframe border=0 width="100%" height ="100%" src="' + url + '"> </iframe>');
        $("#MyDialog").dialog({
            title: t,
            modal: true,
            autoOpen: true,
            height: h,
            width: w,
            resizable: false,
            position: ['right-10', 'top+30'],
            closeOnEscape: false,
            dialogClass: "alert"
        });
    }}