5

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?

1
  • Steve, any traction on this? It seems like an interesting question. I'll upvote it once I have more votes for the day. Commented Feb 28, 2014 at 14:52

2 Answers 2

2
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

0

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', '');">
1
  • 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
    Commented Mar 1, 2013 at 16:34

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.