Thursday, 1 September 2011

Display modal dialog from WebPart code Sharepoint 2010



Calling a modal dialog from Webpart code is as simple as displaying from a application page or in a content editor webpart...

//add javascript for dialog
String myJavascript = "var showMyModalDialog = function() { ” +
var options = { "+
url: targetUrl,
title: 'Custom dialog',
width: 980,
height: 580,
dialogReturnValueCallback: function (dialogResult, returnValue) " +
{
if (dialogResult === 1)
{ // the user accepted the dialog } " +
+"
else { // the user cancelled the dialog } " +
+ " }
};
SP.UI.ModalDialog.showModalDialog(options);
}; "

// Register the script
this.Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "modalDialogBox", myJavascript);

Ads by Google

No comments:

Post a Comment