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

In a webpart, I added a button that should trigger a modal dialog, and display a message when the dialog is closed.

The dialog script is handled by this code :

function OpenGenericForm(formUrl, confirmText) {
    ExecuteOrDelayUntilScriptLoaded(function () {
        SP.UI.ModalDialog.showModalDialog({
            url: formUrl,
            dialogReturnValueCallback: function (dialogResult, returnVlue) {
                RefreshPage(dialogResult);
                if (dialogResult == SP.UI.DialogResult.OK) {
                    SP.UI.Notify.addNotification(confirmText, true);
                }
            } 
        });
    }, 'sp.js');
}

And the button is :

<a id="someid" onclick="OpenGenericForm('/Lists/gen test/NewForm.aspx','some message');return false;" href="#">label of the link</a>

The modal is opened as expected, but when it closes, I can see the notification a quarter of seconds, before the whole page is reloaded (and then my notification disappeared.

Isn't a call to RefreshPage(dialogResult) supposed to reload the page using some kind of ajax?

If not, what the correct way to reload content of webparts using ajax?

share|improve this question
    
Steve, any traction on this? It seems like an interesting question. I'll upvote it once I have more votes for the day. –  Robert Kaucher Feb 28 at 14:52
add comment

2 Answers

function portal_openModalDialogContact(URL) {
    var options = SP.UI.$create_DialogOptions();
    options.url = URL;
    options.width = 600;
    options.dialogReturnValueCallback = Function.createDelegate(null, CloseCallback);
    SP.UI.ModalDialog.showModalDialog(options);
}
function CloseCallback(result, target) {

    window.parent.location.href = window.location.href; //This will refresh your page after popup got closed
} 

This will solve your problem

share|improve this answer
add comment

RefreshPage tells the browser to reload the whole page. You would need to use some functionality like in this post to reload update panels (if your webpart content is not in an update panel, it will reload the whole page regardless): http://encosia.com/easily-refresh-an-updatepanel-using-javascript/

The example from the article uses:

<div id="Container" onclick="__doPostBack('UpdatePanel1', '');">
share|improve this answer
    
Actually, I don't need/want to refresh my webpart, but all webparts in the page, using their builtin refresh. but I think it won't be as easy. I may move my notify script to a postback handler –  Steve B Mar 1 '13 at 16:34
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.