Open modal dialog and refresh the parent page from custom form SharePoint 2010

Written by Keith Tuomi on. Posted in Client Object Model, Javascript

What

You need to open a SharePoint 2010 popup (SPModalDialog) and refresh the parent page on close.

So What

End Users get griefed when they add an amazing new bit of content to SharePoint, but after submitting it’s not immediately visible on the page they just “came from” (even though geeks know the score).

Now What

Add the following code (assuming you are up to snuff on the basics of the SP Modal Dialog methods – here’s a good primer):

<script type="text/javascript">
    function openMyDialog(itemid,title) {
        var options = SP.UI.$create_DialogOptions();
        var layoutsUrlView = SP.Utilities.Utility.getLayoutsPageUrl('WebParts/MyWebPart/ViewDialog.aspx')
        options.url = layoutsUrlView + "?itemid=" + itemid + "&title=" + title;
        options.autosize = true;
        options.dialogReturnValueCallback = Function.createDelegate(null, CloseCallback);
        SP.UI.ModalDialog.showModalDialog(options);
    }
    function CloseCallback(result, target) {
        location.reload(true);
    }
</script>

Now when you close the popup, the parent page is refreshed.

Incoming search terms:

  • sharepoint 2013 client object model open dialog
  • sp ui modaldialog showmodaldialog sharepoint 2013
  • sharepoint 2013 close modal dialog
  • sharepoint 2013 close popup
  • sharepoint list edit form popupwindow dialogreturnvaluecallback as recent added list item
  • sharepoint 2013 sputilities
  • sharepoint 2013 sp ui modaldialog showmodaldialog(o) null
  • sharepoint 2013 sp ui modaldialog height
  • sharepoint 2013 sp ui $create_dialogoptions() in the application page sample
  • SharePoint 2013 open new list item dialog

Tags: , ,

Trackback from your site.

Keith Tuomi

itgroove is a team of dedicated professionals specializing in Microsoft technologies for the small and medium sized business. Our SharePoint practise offers expert level assistance in architecting, implementing, and customising this industry leading collaboration platform.

Comments (1)

  • itgroove

    |

    Thanks for sharing Keith

    Reply

Leave a comment

Follow me on Twitter