Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 265
  • Last Modified:

transferring values from the pop-up window to the parent window

I have an asp.net page that opens a new window. The user selects some options in that new window and clicks Apply button. I need to transfer the values from the pop-up window to the main window and reload the main window to enable it to use the values from a pop-up window. What's the best way to do that?

I created global variables that are accessible by any page and assigned the values to those variables in the code-behind of the pop-up window. Now how do I reload main window to use those values?
0
YZlat
Asked:
YZlat
  • 2
  • 2
2 Solutions
 
TimCotteeCommented:
Hi YZlat,

The easiest way is actually to use javascript to directly write the values back to the main page: for example you could have a button in the popup

<input type=button id="UpdMainPage" value="Update Main Page" onclick="updateValues();">

And some script in the popup that does:

function updateValues()
{
    var parent=window.opener.document;
    parent.getElementById('Field1').value = document.getElementById('Field1');
// and so on for all the values
    self.close(); //close the popup having transferred the values.
}

This way you don't necessarily need to reload the main page even!

Tim Cottee
0
 
YZlatAuthor Commented:
Hi Tim. Thanks for the quick response. the thing is if I don't reload the main page, how will it use the new values?

also I do not pass the value of a control to another control on the parent page, but instead pass a string variable from pop-up to the parent page.

So I figured after assigning the values to the global variable I just reload the parent page. How would I do that using C# (after assigning values to a string variable)?
0
 
Elvio Lujan.Net Senior DeveloperCommented:
add the submit() to your submit button:

btn.Attributes.Add("onclick", "window.opener.document.forms[0].submit(); window.close();");
0
 
TimCotteeCommented:
YZlat,

If by global variables you mean client-side javascript or vbscript variables then you would just use:

window.opener.location.href=window.opener.location.href

Setting the page location of the calling window to the same location will reload that page. If these are application global variables, the same applies really as long as you have posted them in the popup page. You could on postback clear the response so that no content is displayed in the popup and use

Response.Write ("<script language=javascript type=text/javascript>window.opener.location.href=window.opener.location.href;self.close();</script>");

To output the script, it will force the reload of the parent page and close the popup in one go.



Tim
0
 
YZlatAuthor Commented:
I ended up using

Response.Write("<script language='JavaScript'>window.opener.location.reload();</script>")


Thanks guys.

0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now