0

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.

1

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();

Your Answer

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

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