Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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.

share|improve this question
add comment

2 Answers 2

up vote 1 down vote accepted

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.

share|improve this answer
    
Thanks a lot :) –  ar.gorgin Jan 25 '12 at 7:43
    
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
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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