Sunday, February 3, 2013

SharePoint popup how to

Scenario:
I planned to use SharePoint popup in client project.

Solution:
I did a quick POC and here's what you need to do to make it work.

What goes in Parent Window Header ?
Add following JavaScript in the header section :

function OpenMyWebPage(popupTitle, popupUrl) {
        var options = {
            url: popupUrl,
            autoSize: true,
            showClose: true,
            title: popupTitle,
            dialogReturnValueCallback: function (dialogResult) {
                if (dialogResult == SP.UI.DialogResult.OK) {
                    window.document.location.reload(true);
                }
            }
        };
        SP.UI.ModalDialog.showModalDialog(options);
    }
How to launch the Popup
Edit
What goes in Popup Window - Save button at the end ( to refresh the parent window )
Context.Response.Write("<script type='text/javascript'>window.frameElement.commitPopup();</script>");
           Context.Response.Flush();
           Context.Response.End();
What goes in Popup Window - Cancel button
Nothing is needed here
Hidding Ribbon - Add at the end , in case you dont want to display ribbon

0 comments: