'How to access textbox inside grid view of parent page in popup page?

I have a pop up page where I want to get the textbox value which is inside gridview of main page, and populate value in that textbox.

I have tried:

  var Emp = window.opener.document.getElementById('grd_txtEmp');
  Emp.rows[1].cells[3].childNodes[0].value="abc";

My popup page:

  <asp:TemplateField HeaderStyle-BackColor="#C0C0C0" HeaderStyle-BorderColor="Black" HeaderText="Man">
      <ItemTemplate>     
      <table><tr><td>                                       
          <asp:TextBox ID="txtEmpy" runat="server" TextMode="MultiLine"  ontextchanged="txtEmploy_TextChanged" ReadOnly="true" Text='<%# Eval("Empry") %>'  Width="98%"></asp:TextBox>
       </td>
       <td align="right">
       <a href="javascript:window.open('Select.aspx', 'mywindow', 'menubar=1,resizable=1,width=600,height=400, top=200, left=400');">Select</a>   

      </td></tr></table>
      </ItemTemplate>
      
        <HeaderStyle BackColor="Silver" BorderColor="Black"  Width="30%"/>
</asp:TemplateField>


Solution 1:[1]

As far as I understood, you are opening the popup, on clicking of some link or button in the grid view row. If this is correct, then while opening the popup, you can pass the textbox id to the popup as a query string. Then you can set the value to the correct text box from the poped up window. To get the id of the textbox in the current row, you can use jQuery

As an example, you can try this idea Add a css class to the textbox, say, "extdata" Add a css class to the link/button, say, "popupopener" Then add the following jQuery

       $(document).ready(function () {
        $('.popupopener').each(function () {
            $(this).click(function () {
                //If the textbox is at the same level as the link button
                var textBoxId = $(this).closest("table").find('.extdata').attr('id');
                window.open("Select.aspx" + "?textboxid=" + textBoxId, "mywindow", 'menubar=1,resizable=1,width=600,height=400, top=200, left=400');
            }
        );
        });
    });

Change the layout as below

<asp:TemplateField HeaderStyle-BackColor="#C0C0C0" HeaderStyle-BorderColor="Black" HeaderText="Man">
                <ItemTemplate>
                    <table>
                        <tr>
                            <td>
                                <asp:TextBox ID="txtEmpy" CssClass="extdata" runat="server" TextMode="MultiLine" OnTextChanged="txtEmploy_TextChanged" ReadOnly="true" Text='<%# Eval("Empry") %>' Width="98%"></asp:TextBox>
                            </td>
                            <td align="right">
                                <a class="popupopener">Select</a>

                            </td>
                        </tr>
                    </table>
                </ItemTemplate>

                <HeaderStyle BackColor="Silver" BorderColor="Black" Width="30%" />
            </asp:TemplateField>

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1