When we try to invoke the SharePoint modal dialog from visual webpart, sometimes we will get an error as "SP.UI.$create_DialogOptions is not a function". In order to resolve the issue, explicitly call LoadSodByKey function from document ready method of visual webpart.$(document).ready(function () {
LoadSodByKey("sp.js", function () {});
InvokeSPDialog();
}); SharePoint modal dialog: function InvokeSPDialog() {
var diaOptions = SP.UI.$create_DialogOptions();
diaOptions.url = 'http://siteurl/_layouts/15/Test.aspx',
diaOptions.title = "Test";
diaOptions.width = 300;
diaOptions.height = 100;
diaOptions.dialogReturnValueCallback = Function.createDelegate(null, CloseCallBack);
SP.UI.ModalDialog.showModalDialog(diaOptions);
}
function CloseCallBack(result, returnValue) {
alert('ok');
} Hope this resolves the issue!
|