SP.UI.ModalDialog.showModalDialog() Does Not Work Under SharePoint 2013

Migrating from SharePoint 2010 to SharePoint 2013, I have faced this issue "the calls to showModalDialog failed with message that the method cannot be found."


SharePoint 2010  Example:

 var options = SP.UI.$create_DialogOptions();
        options.title = "EMPTY SEARCH BOX";
        options.scroll = 0;
        options.width = 500;
        options.height = 150;
        options.url = "/DocumentManagement/EmptySearch.aspx";
        options.dialogReturnValueCallback = Function.createDelegate(
                       null, portal_modalDialogClosedCallback);
        SP.UI.ModalDialog.showModalDialog(options);


Follow below steps:

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


By doing these changes it must work in SharePoint 2013


SharePoint 2013 Example:


 var options = {
  url: '/DocumentManagement/EmptySearch.aspx?IsDlg=1',
          tite: 'EMPTY SEARCH BOX',
           allowMaximize: false,
            showClose: true,
            width: 500,
             height: 150
       }
       SP.SOD.execute('sp.ui.dialog.js', 'SP.UI.ModalDialog.showModalDialog', options);

Comments

  1. Good one vedi sahab i recently used this in one of my project

    ReplyDelete

Post a Comment

Popular posts from this blog

How to Customize exported excel's cell background color in Datatables

Clear DataTable on button click

Upload multiple attachments to SharePoint List Item using REST API jQuery, along with People Picker Column