Welcome to AspAdvice Sign in | Join | Help

AzamSharp

Some day I will know everything I hope that day never comes

Syndication

Tags

Navigation

Passing Parameters from Child to Parent Window

The scenario is very simple, you have a child window which have input fields and you want to transfer the text/input from the child window to the parent window. By parent window I mean that window that opened the child window.

Here is the code for the parent window:

<form id="form1" runat="server">

<div>

<a href="#" onclick="OpenNewWindow()" >Open a new window</a>

<asp:TextBox ID="txtParent" runat="server" />

</div>

</form>

</body>

</html>

<script language = "javascript" type="text/javascript">

function OpenNewWindow()

{

var newWindow = window.open('PopUp.aspx','MyPopUp','width=200,height=200');

</script>

I am going to populate the txtParent textbox of the parent window from the child window.

Here is the child window:

<form id="form1" runat="server">

<div>

<asp:TextBox ID="txtUserName" runat="server" />

<a href="#" onclick="TransferText()" >Transfer Text to Parent Window</a>

</div>

</form>

</body>

</html>

<script language="javascript" type="text/javascript">

function TransferText()

{

window.opener.form1.txtParent.value = document.getElementById("txtUserName").value;

}

Yup! thats all to it. The window.opener can be used to refer back to the parent window. Please keep in mind that window.opener is not equal to window.parent which, is used in case of frames, iframes.

 

 

Published Tuesday, December 12, 2006 6:16 PM by azamsharp

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# re: Passing Parameters from Child to Parent Window @ Thursday, January 04, 2007 5:08 PM

it's too good vary useful thanks

ankur

# re: Passing Parameters from Child to Parent Window @ Thursday, January 04, 2007 6:44 PM

i wolud like to ask that that what is opner here i didn't get it

ankur

# re: Passing Parameters from Child to Parent Window @ Thursday, January 04, 2007 9:47 PM

window.opener is a reference back to the parent window which, actually opened the popup window.

azamsharp

# re: Passing Parameters from Child to Parent Window @ Monday, March 26, 2007 2:31 PM

This code works great.... in Internet Explorer. It doesn't work in FireFox however. Any suggestions?

Sean

# re: Passing Parameters from Child to Parent Window @ Tuesday, October 02, 2007 5:21 AM

thank you but it doesn't work when using master pages , i mean no value returns , also it doesn't open in IE . is there any update ?? thanks a lot

Gersy

# re: Passing Parameters from Child to Parent Window @ Thursday, October 04, 2007 12:56 PM

Hi Gersy,

When using Master Pages try to locate the ID of the control that you are trying to access. The Content control gives a unique ID to each control that is contained inside it. You can run the page and view the source and you will get the ID.

azamsharp

# re: Passing Parameters from Child to Parent Window @ Sunday, October 21, 2007 4:53 AM

Well Mr.Azam I found great solution for that . this is like dialog wizard.it enables me to manage this in easy way. I want you to take a look you can fiend it here http://www.inchl.nl/ thank you , and Happy Eid !!!

Gersy

# re: Passing Parameters from Child to Parent Window @ Wednesday, November 14, 2007 9:48 AM

Fantastic! I've been looking for something as simply explained as this for ages! Very useful and saved me loads of time Thanks a million

Kevin

Leave a Comment

(required) 
required 
(required) 
Enter the code you see below