5

I have created a dialog with the following code:

function Dialog() {
   var options = {
    url: 'http://mysite/mypage.aspx',
    title: 'My Title',
    allowMaximize: false,
    showClose: true,
    width: 400,
    height: 350,
    dialogReturnValueCallback: RefreshOnDialogClose

  };    
   SP.SOD.execute('sp.ui.dialog.js', 'SP.UI.ModalDialog.showModalDialog', options);
}

this dialog works good and after i click save it refreshes the page, but if i click close or cancel it refreshes the page again.

So I want only when the save button is clicked to refresh page, not when close or cancel is pressed.

Thanks

2
  • are you using a function at RefreshOnDialogClose should you post it ? Commented Dec 17, 2016 at 12:39
  • No I just wrote it there I don't have any function with that name, perhaps it is in any JS script Commented Dec 17, 2016 at 12:50

2 Answers 2

13

You can do the following:

 var options = {
    url: 'https://sp2013dev/sites/dev/Shared%20Documents/Forms/EditForm.aspx?ID=9',
    title: 'My Title',
    allowMaximize: false,
    showClose: true,
    width: 400,
    height: 350,
    dialogReturnValueCallback: function(result){
        if (result == SP.UI.DialogResult.OK) {
            window.location.reload();
        }
        if (result == SP.UI.DialogResult.cancel) {
            //do nothing, modal was closed
        }
    }

  };    
   SP.SOD.execute('sp.ui.dialog.js', 'SP.UI.ModalDialog.showModalDialog', options);  

Be default RefreshOnDialogClose always reloads.

0
6

Try to remove RefreshOnDialogClose and set dialogReturnValueCallback: to a function, and check in this function the dialogResult to refresh on OK only as the following:

 dialogReturnValueCallback: function (dialogResult) {
      if (dialogResult == SP.UI.DialogResult.OK) {
           SP.UI.ModalDialog.RefreshPage(SP.UI.DialogResult.OK);
      }
1

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.