Thursday, February 14, 2013

How to refresh parent page after closing a SP.UI.ModalDialog

var options = {
 
url:'/_layouts/YourAspx/YourPage.aspx',
 title: 'Your Application Page Title',
 allowMaximize: false,
 showClose: true,
 width: 700,
 height: 260,
 dialogReturnValueCallback: RefreshOnDialogClose
 };
SP.UI.ModalDialog.showModalDialog(options);


Key here is the callback function; set it to RefreshOnDialogClose. Dead simple ;-)

4 comments:

  1. How would you wait for workflows to complete or for a specific period of time before executing the refresh?

    ReplyDelete
    Replies
    1. Hi Frederic,

      As for the timed refresh, replace the 'RefreshOnDialogClose' with a function that invokes the SP.UI.ModalDialog.Refresh() method. Within this function, define an interval using the setInterval() method. For example:

      dialogReturnValueCallback: function(dialogResult)
      {
      // if the dialogResult == 1, the function below will refresh the page after three seconds
      setInterval(function() {SP.UI.ModalDialog.RefreshPage(dialogResult);}, 3000);
      };

      To have the parent page refreshed regardless of the dialogResult outcome, replace it with 1 and remove the dialogParameter from the function:

      dialogReturnValueCallback: function()
      {
      setInterval(function() {SP.UI.ModalDialog.RefreshPage(1);}, 3000);
      };


      Achieving a parent page refresh from a workflow when you are in a popup is not that straight forward, maybe not even possible...

      Hope that helps,

      All the best.

      Delete
  2. I want a separate function to be called as well as my parent page should be refreshed... what needs to be done ???

    ReplyDelete