none
Issue calling SP.UI.ModalDialog.showModalDialog(options); RRS feed

  • Question

  • I have custom application page (Details.aspx) that uses 

    DynamicMasterPageFile="~masterurl/custom.master"

     located "{SiteUrl}/_layouts/workflow/Details.aspx" and on that page i have a button that executes the following JavaScript code.

    <script type="text/javascript" language="javascript">
            function OpenDialog() {        
              var options = {
                url: '{SiteUrl}/_layouts/Workflow/DocumentsDialog.aspx',
                title: 'Test Modal Dialog',
                width: 800,
                height: 600,
                dialogReturnValueCallback: CloseCallback
              };
              SP.UI.ModalDialog.showModalDialog(options);
    
            }
          
            function CloseCallback(result, returnValue) {
              alert('Result from dialog was: ' + result);
              if (result == SP.UI.DialogResult.Ok) {
                alert('You clicked Ok');
              }
              else if (result == SP.UI.DialogResult.cancel) {
                alert('You clicked Cancel');
              }
            }
            
        </script>

    I have refrenced on my custom application page (Details.aspx) the following.

                <script type="text/javascript" src="/_layouts/SP.UI.Dialog.js" ></script>    
                <script type="text/javascript" src="/_layouts/SP.UI.Dialog.debug.js" ></script>

    I can navigate to the dialog box directly "{SiteUrl}/_layouts/Workflow/DocumentsDialog.aspx" directly without any issue, however when i try and execute if from my button i get the following error when it hits the  SP.UI.ModalDialog.showModalDialog(options); section of the javascript.

    Error: Microsoft JScript runtime error: Object doesn't support this property or method 

    What am i missing?

    Monday, November 29, 2010 3:33 PM

Answers

  • I figured it out, I had to learn a little bit more about ECMAScipt and it works fine when i changed the following.

    You need to use the ScriptLink and FormDigest controls like this:

            <Sharepoint:ScriptLink ID="ScriptLink1" Name="sp.ui.dialog.js" LoadAfterUI="true" Localizable="false" runat="server"></Sharepoint:ScriptLink>   
            <SharePoint:FormDigest runat="server" />      

    instead of refrencing the .js files like this:

    <script type="text/javascript" src="/_layouts/SP.UI.Dialog.js" ></script>    
    <script type="text/javascript" src="/_layouts/SP.UI.Dialog.debug.js" ></script>

     

    • Marked as answer by GT Hardy Monday, November 29, 2010 9:51 PM
    Monday, November 29, 2010 9:51 PM

All replies

  • interestingly if i use "SP.UI.Modal.OpenPopUpPage('DocumentsDialog.aspx', CloseCallback, 800, 600);" it works fine.

    What is the difference?

    Monday, November 29, 2010 4:19 PM
  • I would have to say it is a problem with your options. Specifically the url. Have you tried it with "url: '/_layouts/Workflow/DocumentsDialog.aspx'"?
    If someone on the forums takes the time to successfully address your question, please return the favor by marking their reply as helpful or as the answer to your question.
    Monday, November 29, 2010 9:33 PM
  • Yes i have tried that and all kinds of things in the url: 'www.bing.com' etc. trying to get it to open anything and it won't.
    Monday, November 29, 2010 9:39 PM
  • I figured it out, I had to learn a little bit more about ECMAScipt and it works fine when i changed the following.

    You need to use the ScriptLink and FormDigest controls like this:

            <Sharepoint:ScriptLink ID="ScriptLink1" Name="sp.ui.dialog.js" LoadAfterUI="true" Localizable="false" runat="server"></Sharepoint:ScriptLink>   
            <SharePoint:FormDigest runat="server" />      

    instead of refrencing the .js files like this:

    <script type="text/javascript" src="/_layouts/SP.UI.Dialog.js" ></script>    
    <script type="text/javascript" src="/_layouts/SP.UI.Dialog.debug.js" ></script>

     

    • Marked as answer by GT Hardy Monday, November 29, 2010 9:51 PM
    Monday, November 29, 2010 9:51 PM
  • Thanks... Its working perfect....

    <Sharepoint:ScriptLink ID="ScriptLink1" Name="sp.ui.dialog.js" LoadAfterUI="true" Localizable="false" runat="server"></Sharepoint:ScriptLink>   
            <SharePoint:FormDigest runat="server" />


    Amit Phule - [SharePoint 2010 & Silverlight 4 Developer]

    Wednesday, April 24, 2013 7:28 AM
  • Hi, just wanted to add for some reason this didn't work for me, I had to change LoadAfterUI="false" (or get rid of this attribute), and add another scriptlink to SP.js, like so:

    <Sharepoint:ScriptLink ID="ScriptLink2" Name="sp.js" Localizable="false" runat="server"></Sharepoint:ScriptLink>

    Cheers, Mike

    Wednesday, April 24, 2013 4:28 PM
  • where are you placing this code? I tried adding the above in the <head> of my custom .aspx page, but I can an error of unknown server tag? any ideas?
    Thursday, May 21, 2015 12:28 PM
  • Try placing code @ below...

    <asp:Content ContentPlaceHolderId="PlaceHolderMain" runat="server">
    
    <script>
    ***code of Modal-Dialog***
    </script>
    
    ***__HTML__***
    
    </asp:Content>
    Hope it works ... 


    - Suyog Patil


    • Edited by Suyog ' Tuesday, September 20, 2016 3:09 PM Removing extra space '
    Tuesday, September 20, 2016 3:08 PM