SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a page with the following javascript on it:

    var myVal = 'something';
                       function(dlgResult, returnValue) {

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
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:

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

Your Answer


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.