I have 2 pages, Cart.aspx and SelectPartner.aspx. And a JavaScript file, popup.js
In Cart.aspx I have a button that opens the page SelectPartner.aspx (as a new window) by the InvokePop() function.
In SelectPartner.aspx I have a gridview (with Selection enabled), a textbox, and buttons Ok and Cancel. This is what I want to do: when I select an item in the gridview, the value of one column is shown in the textbox, and when when I press the button Ok the function ReturnPartner() is called and should close the this window (SelectPartner.aspx) and show the value of this textbox in another textbox in the Cart.aspx page. If I write something into the TextBox in SelectPartner.aspx I can pass that value to the TextBox in the Cart.aspx page, but when I press a select button in the gridview the value is not passed.
I don't know what happens, please help me...
Here is the code of Cart.aspx
<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Cart.aspx.cs" Inherits="NMv01.Cart" %>
<%@ Register TagPrefix="asp" Namespace="AjaxControlToolkit" Assembly="AjaxControlToolkit"%>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
<style type="text/css">
#Select1
{
height: 16px;
width: 24px;
}
</style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<script type="text/javascript" src="popup.js"></script>
<asp:Label ID="lblPartnerId" runat="server" Text="ID del Socio"></asp:Label>
<br />
<asp:TextBox ID="txtPartnerID" runat="server"></asp:TextBox>
<asp:Button ID="btnPartnerId" runat="server" Text="Elegir Socio" />
</asp:Content>
Now SelectPartner.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="SelectPartner.aspx.cs" Inherits="NMv01.catalog.SelectPartner" %>
<!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></title>
<script type="text/javascript" src="popup.js"></script>
<style type="text/css">
.style1
{
width: 100%;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<table class="style1">
<tr>
<td>
</td>
<td>
<asp:GridView ID="grdSelectPartner" runat="server" AutoGenerateColumns="False"
AutoGenerateSelectButton="True" DataKeyNames="PartnerId"
DataSourceID="srcSelectPartner"
onselectedindexchanged="grdSelectPartner_SelectedIndexChanged">
<Columns>
<asp:BoundField DataField="PartnerName" HeaderText="PartnerName"
SortExpression="PartnerName" />
<asp:BoundField DataField="PartnerId" HeaderText="PartnerId" ReadOnly="True"
SortExpression="PartnerId" />
<asp:BoundField DataField="PartnerCity" HeaderText="PartnerCity"
SortExpression="PartnerCity" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="srcSelectPartner" runat="server"
ConnectionString="Data Source=ZUNIGA-PC\SQL1;Initial Catalog=NovamMonetanDB;User ID=sa; pwd=Next2011"
ProviderName="System.Data.SqlClient"
SelectCommand="SELECT [PartnerName], [PartnerId], [PartnerCity] FROM [Partners] ORDER BY [PartnerName]">
</asp:SqlDataSource>
</td>
<td>
</td>
</tr>
<tr>
<td>
</td>
<td>
<asp:Label ID="Label1" runat="server" Text="ID:"></asp:Label>
<asp:TextBox ID="txtPartner" runat="server"></asp:TextBox>
</td>
<td>
</td>
</tr>
<tr>
<td>
</td>
<td>
<asp:Button ID="btnOk" runat="server" Text="OK" OnClientClick="ReturnPartner()" />
<asp:Button ID="btnCancel" runat="server" Text="Cancelar" />
<br />
<br />
</td>
<td>
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
And this is the popup.js file:
function InvokePop(fname) {
val = document.getElementById(fname).value;
// to handle in IE 7.0
if (window.showModalDialog) {
retVal = window.showModalDialog("SelectPartner.aspx?Control1=" + fname, 'Choose Partner', "dialogHeight:360px,dialogWidth:360px,resizable:yes,center:yes,");
document.getElementById(fname).value = retVal;
}
// to handle in Firefox
else {
retVal = window.open("SelectPartner.aspx?Control1=" + fname, 'Choose Partner', 'height=360px,width=360px,resizable=yes,modal=yes');
retVal.focus();
}
}
function ReturnPartner() {
var returnString = document.getElementById('txtPartner').value;
RetrieveControl();
// to handle in IE 7.0
if (window.showModalDialog) {
window.returnValue = returnString;
window.close();
}
// to handle in Firefox
else {
if ((window.opener != null) && (!window.opener.closed)) {
// Access the control.
window.opener.document.getElementById(ctr[1]).value = returnString;
}
window.close();
}
}
function RetrieveControl() {
//Retrieve the query string
queryStr = window.location.search.substring(1);
//Retrieve the control passed via querystring
ctr = queryStr.split("=");
}