I have two pages Parent.aspx and PopupWin.aspx.
When i open a popup window and select a value from dropdown and click select button,the dropdown on my main page should also show same value selected.
bellow is my code
Parent.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Parent.aspx.cs" Inherits="_Parent" %>
<!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>Parent Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<asp:DropDownList ID="ddlNames" runat="server">
<asp:ListItem Text="Mudassar Khan" Value="1"></asp:ListItem>
<asp:ListItem Text="John Hammond" Value="2"></asp:ListItem>
<asp:ListItem Text="Mike Stanley" Value="3"></asp:ListItem>
</asp:DropDownList>
<td>
<asp:Button ID="Button1" Text="Open PopUp" runat="server" OnClientClick="return SelectName()" />
</td>
</tr>
</table>
<script type="text/javascript">
var popup;
function SelectName() {
popup = window.open("PopupWin.aspx" , "Popup", 'height=250,width=250,resizable=yes,modal=yes,center=yes');
popup.focus();
return false
}
</script>
</div>
</form>
</body>
</html>
PopupWin.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="PopupWin.aspx.cs" Inherits="PopupWin" %>
<!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>Popup Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:DropDownList ID="ddlNames" runat="server">
<asp:ListItem Text="Mudassar Khan" Value="1"></asp:ListItem>
<asp:ListItem Text="John Hammond" Value="2"></asp:ListItem>
<asp:ListItem Text="Mike Stanley" Value="3"></asp:ListItem>
</asp:DropDownList>
<br />
<asp:Button ID="Button1" Text="Select" runat="server" OnClientClick="return SelectName()" />
<script type="text/javascript">
function SelectName() {
if (window.opener != null && !window.opener.closed) {
var form = window.opener.document.getElementsByTagName("form")[0];
var txtName = GetElement(form, "span", "ddlNames");
txtName.innerHTML = document.getElementById("ddlNames").Value
;
}
return false;
}
function GetElement(parent, tagName, id) {
var elem = parent.getElementsByTagName(tagName);
for (var i = 0; i < parent.getElementsByTagName(tagName).length; i++) {
if (elem[i].id.indexOf(id) != -1) {
return elem[i];
}
}
return null;
}
</script>
</div>
</form>
</body>
</html>
Pleas Help me.