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

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.

client object model, close modal dialog sharepoint, closecallback

Comments (2)

Leave a Reply to itgroove Cancel reply

Your email address will not be published. Required fields are marked *