Dot Net Learning Zone Blog

A blog about to learn Dot Net

How to Pass Value from Parent to Child popup and Child popup to Parent in ASP.net

Posted by Rajesh on March 10, 2009

I have created two pages – Parent.aspx and Child.aspx

Parent.aspx:-

<%@ Page Language=”C#” AutoEventWireup=”true” CodeFile=”Parent.aspx.cs” Inherits=”_Default” %>

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head runat=”server”>
<title>Untitled Page</title>

<script language=”javascript” type=”text/javascript”>
function OpenPopUP()
{
window.open (‘Child.aspx’,'Child’,'toolbar=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,width=320x,height=350px,top=200px,left=100px’);
return false;
}

</script>
</head>
<body>
<form id=”form1″ runat=”server”>
<div>
<table>
<tr>
<td>
Name
</td>
<td>
<asp:TextBox ID=”txtName” runat=”server” Text=”"></asp:TextBox>
</td>
<td>
<asp:Button ID=”btnSearch” runat=”server” Text=”Search” OnClientClick=”OpenPopUP();” />
</td>
</tr>
</table>
</div>
</form>
</body>
</html>

Child.aspx :-

<%@ Page Language=”C#” AutoEventWireup=”true” CodeFile=”Child.aspx.cs” Inherits=”Child” %>

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head runat=”server”>
<title>Untitled Page</title>

<script language=”javascript” type=”text/javascript”>
function ValuePatentToChild()
{
var Name =  window.opener.document.forms[0].txtName.value;
var setName =  document.getElementById (‘txtChild’);
setName.value =  Name;

}

function ValueChildToParent()
{
var Name =  document.getElementById (‘txtChild’).value;
window.opener.document.forms[0].txtName.value =  Name;
self.close();
}

</script>

</head>
<body onload=”ValuePatentToChild();”>
<form id=”form1″ runat=”server”>
<div>
<table>
<tr>
<td>
<asp:TextBox ID=”txtChild” runat=”server” Text=”"></asp:TextBox>
</td>
<td>
<asp:Button ID=”btnClose” runat=”server” Text=”Close” OnClientClick=”ValueChildToParent();” />
</td>
<td>
</td>
</tr>
</table>
</div>
</form>
</body>
</html>

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <pre> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>