7

On button click I am opening a modal popup and containing a custom webpart. The custom webpart inside the modal popup has a button, on click of this I want to open another modal popup but while doing this I want to close the parent modal popup.

I was not able to to this so I used Response.Redirect("Test.aspx"); but this opens the page inside the same modal dialog, with master page and no ribbons. I don't want the SP ribbon nor do I want the masterpage. I detached the master page for that particular page but I still get the page with masterpage. Does any one know how to do this?

Please guide me as to how to close parent Modal Dialog and at same time open a new Modal Dialog or any other method in which the Test Page is shown in the same modal dialog.

Code:

function openModalDialogYourDetails(Stringurl, width, height,modaltype,fieldname,empname) {
    var modaltitle="";
    if(modaltype==1)//Edit Modal Dialog
    {
    modaltitle="Effective Date changes for " + fieldname + " - " + empname ;
    }
    else if(modaltype==2)//History Modal Dialog
    {
    modaltitle=fieldname + " History - " + empname;
    }

        //Check what has caused the modal to open and set hidden variable
        if(Stringurl.indexOf('Job') !== -1)
            document.getElementById("<%=Modalcause.ClientID%>").value = "Job";
        if(Stringurl.indexOf('work') !== -1)
            document.getElementById("<%=Modalcause.ClientID%>").value = "work";

         options = SP.UI.$create_DialogOptions();
        if(modaltitle!="")
        {
        options.title = modaltitle;
        }
        options.width = width;
        options.height = height;
        options.url = Stringurl;
        options.dialogReturnValueCallback = Function.createDelegate(null, modalDialogClosedCallback);
        SP.UI.ModalDialog.showModalDialog(options);

    }

and closeCallBack function as mentioned in the answer

    function modalDialogClosedCallback(dialogResult, returnValue) { 
    // Depending on what data you get in your 'result' param 
    // your logic to open the new dialog goes here. 

    alert(dialogResult);
    alert(returnValue);

    var options = SP.UI.$create_DialogOptions(); 
    options.width = 800; 
    options.height = 650; 
    options.url = dialogResult; 
    SP.UI.ModalDialog.showModalDialog(options); 
}
2
  • Hi, perhaps it is obvious for all of you but I don't know where to put the javascript. Into the .ascx? I want to use a visual webpart in the retriever-modal which gets a value from my first webpart which is on top of newform.aspx and I just don't get the clue at the moment. Would be great to have a tutorial for this whole action.
    – Dominik
    Dec 19, 2012 at 13:46
  • @Dominik yes put the js in ascx in script tag. Post a question as to exact what you want.
    – Ishan
    Dec 20, 2012 at 5:20

3 Answers 3

2

To do so you'd have to rely on the callback of the dialog to open another dialog.

Example:

var options = SP.UI.$create_DialogOptions();
options.width = 500;
options.height = 250;
options.url = "/_layouts/MyApplicationPage.aspx";
options.dialogReturnValueCallback = Function.createDelegate(null, modalDialogClosedCallback);
SP.UI.ModalDialog.showModalDialog(options);

function modalDialogClosedCallback(dialogResult, returnValue) {
    // Depending on what data you get in your 'result' param
    // your logic to open the new dialog goes here.
    var options = SP.UI.$create_DialogOptions();
    options.width = 500;
    options.height = 250;
    options.url = dialogResult;
    SP.UI.ModalDialog.showModalDialog(options);
}

In order to make sure that the modalDialogClosedCallback gets the data needed to open a new modalDialog. In the application page add this to your buttons click event SP.UI.ModalDialog.commonModalDialogClose(dialogResult, returnValue). It's a method which will close the modalDialog and send data to the dialogReturnValueCallback parameter you set in options.

Example:

<asp:Button ID="btn" runat="server" OnClick="javascript:SP.UI.ModalDialog.commonModalDialogClose('/_layouts/test.aspx', 'Dialog closed')" Text="Open Test" />

So in your applicationpage, make sure that dialogResult contains the URL for the new page to be opened in the new modalDialog.

3
  • Dandroid's answer is great for the modal issues. The other issue you talk about though, relating to not having the master page show up in modal windows, can be resolved by adding the CSS class s4-notdlg to any elements in the master page that you don't want visible in the modal window. Jul 12, 2012 at 13:13
  • I added btnEdit.Attributes.Add("onClick", "SP.UI.ModalDialog.modalDialogClosedCallback('" + HdnBtnEditURL.Value + "', 'Dialog closed')"); and function modalDialogClosedCallback(dialogResult, returnValue) but it dint work. where to set the otion for options.dialogReturnValueCallback = Function.createDelegate(null, modalDialogClosedCallback);
    – Ishan
    Jul 12, 2012 at 13:13
  • I have done as the changes as updated in the question
    – Ishan
    Jul 12, 2012 at 13:20
2
Response.Redirect(HdnBtnEditURL.Value+"&IsDlg=1"); 

The above piece of code worked for me. It opens a new page in the same modal dialog &IsDlg=1 this querystring param disables the master page attached to the webpage.

1

You can pass a callback to the SP.UI.ModalDialog class that specifies a JavaScript function you can call from the first dialog as a result of the first dialog finishing. This function will be in the main parent page and can then call the second popup.

http://msdn.microsoft.com/en-us/library/ff409609.aspx

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.