SP.UI.ModalDialog.showModalDialog() do not work in SharePoint 2013

Check out Best Alternative to InfoPath


Introduction:
Have you ever tried using SP.UI.ModalDialog.showModalDialog(options) in SharePoint 2013. I discovered some strange behavior…


After migrating my code from SharePoint 2010 to SharePoint 2013 the calls to showModalDialog failed with message that the method cannot be found (javascript). When checking it in IE Developer Tools this isn’t surprising at all. The required js-file isn’t loaded.

But why? I guess it must be the new SOD-Model (Script on Demand) that was introduced in SharePoint 2013.

Read some SharePoint tutorials

SharePoint Server 2016 Installation FREE PDF guide

Export SharePoint designer List workflow from one site to another site

Update or Delete SharePoint 2010 List Item using Javascript Object Model

SharePoint 2010 Example:



function ShowServerInformation() {
var options = {
url: ‘/_layouts/Management/GeneralInformation.aspx’,
tite: ‘Management Information’,
allowMaximize: false,
showClose: true,
width: 430,
height: 230
};
SP.UI.ModalDialog.showModalDialog(options);
return false;
}

It’s very easy to fix this problem.

Follow below steps:

1. Remove the Java Script reference.
2. <script src=”/_layouts/sp.js” type=”text/javascript”></script>
3. <script src=”/_layouts/SP.UI.Dialog.js” type=”text/javascript”></script>
4. Add to the url variable “?IsDlg=1″`
5. Replace the command SP.UI.ModalDialog.showModalDialog() with the new command SP.SOD.execute(‘sp.ui.dialog.js’, ‘SP.UI.ModalDialog.showModalDialog’, options);

After this few changes your solution will work correctly.

SharePoint 2013 Example:

function ShowServerInformation(featureId) {
var options = {
url: ‘/_layouts/Management/GeneralInformation.aspx?IsDlg=1’,
tite: ‘Management Information’,
allowMaximize: false,
showClose: true,
width: 430,
height: 230
}
SP.SOD.execute(‘sp.ui.dialog.js’, ‘SP.UI.ModalDialog.showModalDialog’, options);

return false;
}

Notice: I first tried the “executeOrDelayUntilScriptLoaded”-function. But it was not of much help. It just “swallowed” my function call but never executed it because the js-file I specified was never loaded.


Hope this helps anyone out there!


You May Also like the Following SharePoint Online Tutorials:

About Sagar Pardeshi

I am Developer working on Microsoft Technologies for the past 6+years. I am very much passionate about programming and my core skills are SharePoint, ASP.NET & C#,Jquery,Javascript,REST. I am running this blog to share my experience & learning with the community I am an MCP, MCTS .NET & Sharepoint 2010, MCPD Sharepoint 2010, and MCSD HTML 5,Sharepoint 2013 Core Solutions. I am currently working on Sharepoint 2010, MOSS 2007, Sharepoint 2013,Sharepoint 2013 App Dev, C#, ASP.NET, and SQL Server 2008.

View all posts by Sagar Pardeshi →