Javascript function doesn't get textbox value (text) after selecting an item in gridview
<p>I have 2 pages, Cart.aspx and SelectPartner.aspx. And a javascript file, popup.js</p>

<p>In Cart.aspx I have a button that opens the page SelectPartner.aspx (as a new window) by the InvokePop() function.</p>

<p>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 fuction 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.</p>

<p>I don't know what happens, please help me...</p>

<p>Here is the code of Cart.aspx</p>

<pre><code>&lt;%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Cart.aspx.cs" Inherits="NMv01.Cart" %&gt;
&lt;%@ Register TagPrefix="asp" Namespace="AjaxControlToolkit" Assembly="AjaxControlToolkit"%&gt;
&lt;asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server"&gt;
    &lt;style type="text/css"&gt;
        #Select1
        {
            height: 16px;
            width: 24px;
        }
    &lt;/style&gt;
&lt;/asp:Content&gt;

&lt;asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server"&gt;
&lt;script type="text/javascript" src="popup.js"&gt;&lt;/script&gt;
    &lt;asp:Label ID="lblPartnerId" runat="server" Text="ID del Socio"&gt;&lt;/asp:Label&gt;
                &lt;br /&gt;
                &lt;asp:TextBox ID="txtPartnerID" runat="server"&gt;&lt;/asp:TextBox&gt;
                &amp;nbsp;&amp;nbsp;&lt;asp:Button ID="btnPartnerId" runat="server" Text="Elegir Socio" /&gt;
                &amp;nbsp;


&lt;/asp:Content&gt;
</code></pre>

<p>Now SelectPartner.aspx</p>

<pre><code>&lt;%@ Page Language="C#" AutoEventWireup="true" CodeBehind="SelectPartner.aspx.cs" Inherits="NMv01.catalog.SelectPartner" %&gt;

&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;

&lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
&lt;head runat="server"&gt;
    &lt;title&gt;&lt;/title&gt;
    &lt;script type="text/javascript" src="popup.js"&gt;&lt;/script&gt;
    &lt;style type="text/css"&gt;
        .style1
        {
            width: 100%;
        }
    &lt;/style&gt;
&lt;/head&gt;
&lt;body&gt;
    &lt;form id="form1" runat="server"&gt;
    &lt;div&gt;

        &lt;table class="style1"&gt;
            &lt;tr&gt;
                &lt;td&gt;
                    &amp;nbsp;&lt;/td&gt;
                &lt;td&gt;
                    &lt;asp:GridView ID="grdSelectPartner" runat="server" AutoGenerateColumns="False" 
                        AutoGenerateSelectButton="True" DataKeyNames="PartnerId" 
                        DataSourceID="srcSelectPartner" 
                        onselectedindexchanged="grdSelectPartner_SelectedIndexChanged"&gt;
                        &lt;Columns&gt;
                            &lt;asp:BoundField DataField="PartnerName" HeaderText="PartnerName" 
                                SortExpression="PartnerName" /&gt;
                            &lt;asp:BoundField DataField="PartnerId" HeaderText="PartnerId" ReadOnly="True" 
                                SortExpression="PartnerId" /&gt;
                            &lt;asp:BoundField DataField="PartnerCity" HeaderText="PartnerCity" 
                                SortExpression="PartnerCity" /&gt;
                        &lt;/Columns&gt;
                    &lt;/asp:GridView&gt;
                    &lt;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]"&gt;
                    &lt;/asp:SqlDataSource&gt;
                &lt;/td&gt;
                &lt;td&gt;
                    &amp;nbsp;&lt;/td&gt;
            &lt;/tr&gt;
            &lt;tr&gt;
                &lt;td&gt;
                    &amp;nbsp;&lt;/td&gt;
                &lt;td&gt;
                    &lt;asp:Label ID="Label1" runat="server" Text="ID:"&gt;&lt;/asp:Label&gt;
                    &amp;nbsp;&lt;asp:TextBox ID="txtPartner" runat="server"&gt;&lt;/asp:TextBox&gt;
                &lt;/td&gt;
                &lt;td&gt;
                    &amp;nbsp;&lt;/td&gt;
            &lt;/tr&gt;
            &lt;tr&gt;
                &lt;td&gt;
                    &amp;nbsp;&lt;/td&gt;
                &lt;td&gt;
                    &lt;asp:Button ID="btnOk" runat="server" Text="OK" OnClientClick="ReturnPartner()" /&gt;
                    &amp;nbsp; &lt;asp:Button ID="btnCancel" runat="server" Text="Cancelar" /&gt;
                    &lt;br /&gt;
                    &lt;br /&gt;
                &lt;/td&gt;
                &lt;td&gt;
                    &amp;nbsp;&lt;/td&gt;
            &lt;/tr&gt;
        &lt;/table&gt;

    &lt;/div&gt;
    &lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;
</code></pre>

<p>And this is the popup.js file:</p>

<pre><code>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) &amp;&amp; (!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("=");
}
</code></pre>
