Solved

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

Posted on 2006-11-30
5
258 Views
Last Modified: 2008-02-01
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
Comment
Question by:YZlat
  • 2
  • 2
5 Comments
 
LVL 43

Expert Comment

by:TimCottee
ID: 18045494
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
 
LVL 35

Author Comment

by:YZlat
ID: 18045531
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
 
LVL 18

Accepted Solution

by:
Elvio Lujan earned 125 total points
ID: 18045575
add the submit() to your submit button:

btn.Attributes.Add("onclick", "window.opener.document.forms[0].submit(); window.close();");
0
 
LVL 43

Assisted Solution

by:TimCottee
TimCottee earned 125 total points
ID: 18045588
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
 
LVL 35

Author Comment

by:YZlat
ID: 18045780
I ended up using

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


Thanks guys.

0

Featured Post

ScreenConnect 6.0 Free Trial

Want empowering updates? You're in the right place! Discover new features in ScreenConnect 6.0, based on partner feedback, to keep you business operating smoothly and optimally (the way it should be). Explore all of the extras and enhancements for yourself!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

832 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question