3

I have a Web Part with a grid view and a linkbutton for add item.

I use this code for show modal dialog when linkbutton click .

AddLinkButton.Attributes.Add("onclick",javascript:SP.UI.ModalDialog.ShowModalDialog({url:''});javascript:return false;);

I want refresh the page when modaldialog close.

1

You need to use showModalDialog's dialogReturnValueCallback and in the callback refresh the parent window.

//Using the DialogOptions class.
var options = SP.UI.$create_DialogOptions();

options.title = "My Dialog Title";
options.url = "/_layouts/DialogPage.aspx";
// some other options if needed
options.dialogReturnValueCallback = Function.createDelegate(null, CloseCallback);
SP.UI.ModalDialog.showModalDialog(options);

function CloseCallback(result, target) {
    location.reload(true);
}

You can also define the options using generic object.

1
  • I have tried all of them only Reload(true) works but default message of postback is not acceptable. so still did not found right solution to refresh parent page fully.
    – user14162
    Jan 15 '13 at 21:32
4

The better way to check return value and use RefreshPage method:

function showDialog(){
 SP.UI.ModalDialog.showModalDialog({
    url: urlToOpen,
    title: "title",
    allowMaximize: true,
    showClose: true,
    width: 800,
    height: 600,
    dialogReturnValueCallback: silentCallback
    });
}
function silentCallback(dialogResult, returnValue) {
    switch (dialogResult) {
        case SP.UI.DialogResult.cancel:
            break;
        default:
            SP.UI.ModalDialog.RefreshPage(SP.UI.DialogResult.OK);
            break;
    }
}

For example, you may not need to do refresh if dialog closed using close button.

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.