Friday, March 1, 2013

How to handle SharePoint Poup Close event and return values in Parent Page(Very Basic ).

Code to insert a Popup in any SharePoint Product, In the first page we need to add this code :

function openPopup()
{
var options = SP.UI.$create_DialogOptions();

options.width = 900;
options.height = 600;
options.resizable = 1;
options.scroll = 1;
options.url = 'pageURL';
options.dialogReturnValueCallback = Function.createDelegate(null, CloseCallback);
if(SP.UI.ModalDialog.showModalDialog(options)) {
var y = $(window).scrollTop();
        var boxBorder = $(window).height() - $(".ms-dlgContent").height();
        y = y + boxBorder / 2;
        $(".ms-dlgContent").css({ position: 'absolute', top: y });
}
}

function CloseCallback(result, target)
{
 if(result == SP.UI.DialogResult.OK) {
       alert('
Value got from POPUP on OK : ' +target);
           }
    if(result == SP.UI.DialogResult.cancel) {    

       alert('Value got from POPUP on Cancel : ' +target);
        } 

}


On the PopUp Page we need to put these two code on the events we want to Close our popup as per our need of Cancel & OK handling (Such as a button click or any event) :

 SP.UI.ModalDialog.commonModalDialogClose(SP.UI.DialogResult.OK, 'Value return to the Parent Page on OK');

 SP.UI.ModalDialog.commonModalDialogClose(SP.UI.DialogResult.Cancel, 'Value return to the Parent Page on Cancel');

Very basic and simple:)




No comments:

Post a Comment