2

I have a button in a modal popup, on clicking that button another modal popup opens on top of that. Now I want to refresh the containing page of parent modal dialog on closing child popup.

my code snippet in parent popup :

function OpenModalPopup(_url) {
        var options = {
            url: _url,
            title: "Modal Popup",
            allowMaximize: true,
            showClose: true,
            dialogReturnValueCallback: Function.createDelegate(null, closewindow)
        };
        SP.UI.ModalDialog.showModalDialog(options);
    }

    function closewindow() {
    SP.UI.ModalDialog.RefreshPage(SP.UI.DialogResult.OK);        
    }

But it refreshes the full page

1

Found a way to implement the scenario.

1st popup code (from where the second popup opens) ~

HTML in Page 1 :

<input id="sampleButtonParent" type="button" value="Open Modal Popup" onclick="OpenModalPopup('http://sampleurl.com/')" />

JS in Page 1:

function OpenModalPopup(_url) {
    var options = {
        url: _url,
        title:  "Modal Popup",
        allowMaximize: true,
        showClose: true,
        dialogReturnValueCallback: Function.createDelegate(null, popupClose)
    };
        SP.UI.ModalDialog.showModalDialog(options);
}

function popupClose(result, value) {
    if (result != 0)
        location.reload(true);
}

2nd popup code ~

HTML in Page 2:

<input type="button" id="sampleButtonChild" value="Cancel and Refresh" onclick="closePopup();" />

JS in Page 2:

function closePopup() {
        SP.UI.ModalDialog.commonModalDialogClose(1, 1);
    };

Alternatively if you are performing any calculation in the server side you can write this code-block in the button click event at the code-behind instead of writing 'JS in Page 2'

Code-Behind in Page 2:

this.Page.ClientScript.RegisterStartupScript(this.GetType(), "closeModalPopup", "SP.UI.ModalDialog.commonModalDialogClose(1, 1);", true);
|improve this answer|||||
1

What you should do is on CallBack refresh the dialog elements.

For example: on parent dialog load you might be executing ready function. Call that function once the child dialog closes

function closewindow() {
    //Child Closed
    RefreshParentElements();
}
|improve this answer|||||
  • Thanks for the answer. This is useful. I don't have enough reputation yet to vote it up. Otherwise would have done gladly :) – Anirban Bera Dec 3 '14 at 18:31
  • @AnirbanBera No Problem. I have voted up your question :) – Amal Hashim Dec 3 '14 at 18:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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