.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Articles >> SharePoint >> Post New Resource Bookmark and Share   

 Subscribe to Articles

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

Posted By:Sagar Pardeshi       Posted Date: January 24, 2014    Points: 200    Category: SharePoint    URL: http://www.dotnetspark.com  

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

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.

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.

1.       Remove the Java Script reference.

  1.        <script src="/_layouts/sp.js" type="text/javascript"></script> 
  2.       <script src="/_layouts/SP.UI.Dialog.js" type="text/javascript"></script>
  3.       Add to the url variable "?IsDlg=1"`
  4.       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!


 Subscribe to Articles

     

Further Readings:

Responses
Author: Kaviya Balasubramanian         Company URL: http://www.dotnetspark.com
Posted Date: January 30, 2014

Thanks. This is really very helpful Post.

Post Comment

You must Sign In To post reply
Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend