1

I am trying to open a SharePoint aspx file in the layouts folder in a dialog box.

This file is designed to be opened in a dialog box so I dont need '?IsDlg=1'

The issue is that the page loads values from POST data. For the examples I will be trying to send the sites title. I have tried multiple methods..

METHOD 1: using 'args' option parameter

If unfamillar here is an msdn like to the options http://msdn.microsoft.com/en-us/library/ff410058(v=office.14).aspx

 var options ={ 
    title: 'Sending POST Data',
    autoSize:true,
    args: { myDocTitle : document.title },
    url: 'https://'+window.location.hostname+'/_layouts/targetFile.aspx'
  };
  SP.UI.ModalDialog.showModalDialog(options);

RESULT : Page Loads, No data. submit page form works

METHOD 2: Pass FormLike Object as argument

 var myObj = new Object();
 myObj.myDocTitle = document.title;

 var options ={ 
    title: 'Sending POST Data',
    autoSize:true,
    args: myObj,
    url: 'https://'+window.location.hostname+'/_layouts/targetFile.aspx'
  };
  SP.UI.ModalDialog.showModalDialog(options);

RESULT: Page Loads, No Data. sumbit page form works

Method 3: Use jQuery Post show data

 function showObj(data){
   var ele = document.createElement('div');
   ele.innerHTML=data
   var options ={ 
      title: 'Sending POST Data',
      autoSize:true,
      html:ele
    };
    SP.UI.ModalDialog.showModalDialog(options);
  }
  jQuery.post('https://'+window.location.hostname+'/_layouts/targetFile.aspx',{ myDocTitle : document.title },function(data){showObj(data);});

RESULT: Page Loads with Data, submitting page form doesnt do anything

METHOD 4: Submit post within dialog

   var ele = document.createElement('div');
   ele.innerHTML='<form id="myForm" method="post" action="https://'+window.location.hostname+'/_layouts/targetFile.aspx+'" ><input type="hidden" name="myDocTitle" value="'+document.title+'" /></form>"
   var options ={ 
      title: 'Sending POST Data',
      autoSize:true,
      html:ele
    };
    SP.UI.ModalDialog.showModalDialog(options);
    jQuery("#myForm").submit();

RESULT: Redirects whole browser but has data & sumbit form works

I am trying to avoid creating a layout page just for the redirect

  • did you sort this one out? – nhenrique Jun 15 '16 at 12:11
  • I replicated the layouts file and adjusted it to use queryString parameters instead. This allowed the values to be successfully received when the form opened – user13186 Jun 26 '16 at 16:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.