title: Passing values from Grid-View inside Modal popup Extender to the text box of parent form
body: <p>I have a form with some text boxes and a button, which when clicked (button), a modalpopup extender will open with values display in grid-view (values from database), </p>
  
  <p>If the user select any row, the name of the selected person must display in the text box of the parent form as shown below;</p>
  
  <p><img src="https://i.stack.imgur.com/CwEru.png" alt="enter image description here"></p>
  
  <p>I have written this code,</p>
  
  <p><strong>C# Code:</strong></p>
  
  <pre><code>//GridView inside the Modal popup
   protected void grdPersonDetails_SelectedIndexChanged(object sender, EventArgs e)
          {
              GridViewRow row = grdPersonDetails.SelectedRow;
  
              Session["testSession"] = row.Cells[0].Text;
              ViewState["testViewState"] = row.Cells[0].Text;
              ChargeFilterModalDialogExtender.Hide();
              txtPersonName.Text = (string) ViewState["sometest"];
              txtPersonName.Text = (string) Session["sometest"];
          }
  </code></pre>
  
  <p><strong>ASP Code:</strong></p>
  
  <pre><code> &lt;asp:Label ID="Label1" runat="Server" Text="Person Name:"&gt;&lt;/asp:Label&gt;
          &lt;asp:TextBox runat="Server" ID="txtPersonName" /&gt;
  
          &lt;asp:Button runat="server" ID="btnSelectPerson" Text="Select Person" /&gt;
  
   &lt;ajax:ModalPopupExtender ID="ChargeFilterModalDialogExtender" runat="server" TargetControlID="btnSelectPerson" CancelControlID="BtnCloseChargeFilterControl" Drag="false" PopupControlID="Dialog_ChargeFilter" Enabled="True" BackgroundCssClass="modalBackground" /&gt;
  
      &lt;asp:Button ID="BtnShowDialog" Style="display: none" runat="server" Width="120" Text="Filter Charges" ToolTip="show Chargefilter-Dialog" /&gt;
  
      &lt;asp:Panel ID="Dialog_ChargeFilter" CssClass="modalPopup" runat="server"&gt;
          &lt;asp:Panel ID="DialogHeaderFrame" CssClass="DialogHeaderFrame" runat="server"&gt;
              &lt;asp:Panel ID="DialogHeader" runat="server" CssClass="DialogHeader" ScrollBars="Auto"&gt;
                  &amp;nbsp;&lt;asp:Label ID="LblPopupHeader" runat="server" Text="Charge-Filter" /&gt;
              &lt;/asp:Panel&gt;
          &lt;/asp:Panel&gt;
  
          &lt;asp:UpdatePanel ID="UpdGrdCharge" runat="server" UpdateMode="conditional" ChildrenAsTriggers="false"&gt;
              &lt;ContentTemplate&gt;
                  &lt;asp:Button ClientIDMode="Static" ID="BtnCloseChargeFilterControl" Text="close filter" ToolTip="close filter-dialog" CausesValidation="false" Width="150px" runat="server" OnClick="BtnCloseChargeFilterControl_Click" /&gt;&lt;br /&gt;
                  &lt;table border="1"&gt;
                      &lt;tr&gt;
  
                          &lt;td dir="rtl"&gt;
  
                              &lt;asp:GridView ID="grdPersonDetails" runat="server" AutoGenerateColumns="False" DataKeyNames="PersonName,PersonEmail" DataSourceID="TempSqlDataSource" OnSelectedIndexChanged="grdPersonDetails_SelectedIndexChanged"&gt;
                                  &lt;Columns&gt;
                                      &lt;asp:BoundField DataField="PersonName" HeaderText="Person Name" ReadOnly="True" SortExpression="PersonName" /&gt;
                                      &lt;asp:BoundField DataField="PersonEmail" HeaderText="Person Email" ReadOnly="True" SortExpression="PersonEmail" /&gt;
                                      &lt;asp:TemplateField HeaderText="Select"&gt;
                                          &lt;ItemTemplate&gt;
                                              &lt;asp:Button ID="Button1" runat="server" CommandName="Select" Text="Button" /&gt;
                                          &lt;/ItemTemplate&gt;
                                      &lt;/asp:TemplateField&gt;
  
                                  &lt;/Columns&gt;
                              &lt;/asp:GridView&gt;
                          &lt;/td&gt;
                      &lt;/tr&gt;
                  &lt;/table&gt;
                  &lt;asp:SqlDataSource ID="TempSqlDataSource" runat="server" ConnectionString="&lt;%$ ConnectionStrings:ConnectionString %&gt;" ProviderName="&lt;%$ ConnectionStrings:ConnectionString.ProviderName %&gt;" SelectCommand="select * from person.persons"&gt;&lt;/asp:SqlDataSource&gt;
              &lt;/ContentTemplate&gt;
          &lt;/asp:UpdatePanel&gt;
      &lt;/asp:Panel&gt;
  </code></pre>
  
  <p><strong>The issue is that when I am selecting a person in the grid-view (inside the modal popup), the selected person name not appear in the related text box in the parent form. (when debugging it, it shows that the value of person name set in the text box)</strong></p>