Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I have a page with the following javascript on it:

    var myVal = 'something';
    Pub.Ribbon.PubRibbonComponent.launchDialog('_layouts/RteUploadDialog_Advanced.aspx', 
                                               SP.Publishing.Resources.media_UploadPreview, 
                                               null, 
                                               null, 
                                               Function.createDelegate(this, 
                       function(dlgResult, returnValue) {
                               alert(myVal);
                }));

This is basically opening a modal window that does some stuff, and then there is a callback function that alerts myVal. Is it possible for me to set myVal from javascript in the modal window that is opened by launchDialog? Alternatively, can I set the returnValue parameter of my callback function from javascript in the modal window?

So far I have tried the following:

window.opener.myVal = 'something new';
opener.myVal = 'something new';
myVal = 'something new';

but myVal is never available.

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

You shouldn't try to access anything from the parent page this will introduce a way to thight coupling between your pages.

Instead as you mention you should use the returnValue, by specifying that in the modal dialog.

If you close from the modal dialog using JavaScript just use SP.UI.ModalDialog.commonModalDialogClose(dialogResult, returnVal);

If you need to close the dialog from Server Side code use:

this.Page.Response.Clear();
this.Page.Response.Write(
  "<script type=\"text/javascript\"> 
   window.frameElement.commonModalDialogClose(1, 'ReturnValue From C#')
   </script>");
this.Page.Response.End();
share|improve this answer
    
THANK YOU!!!!!! –  Abe Miessler Aug 22 '12 at 16:01
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.