title: problem handling Gridview_SelectIndexChanging event with an UpdatePanel ASP.NET
body: <p>i will try to explain what i have, what i'm trying to do and what is my problem</p>
  <p>what i have:
  i have a modal with and update panel (i need it because the postback closes my modal) that has two text box, a button and a gridview.
  in the textbox i write the name and the surname of a person and with the button i retrieve the data and put it in a gridview.
  the gridview has a control to select the row that i want, with that row, i use the data from first three cells to change some hidenField values to use in another function.
  in the bottom of the modal i have the add button that only changes a textbox to show that i have the correct data. that button is not enabled by default and the event must enable it</p>
  <p>what i want:
  i want to select the row that i need, enable the add button and fetch the data in my textbox.</p>
  <p>where is my problem:
  when i select my row, selectedindexchanging fires but nevers enables the add button so cant fetch my textbox for using it</p>
  <p>code:</p>
  <p>front code:</p>
  <pre><code>&lt;div class=&quot;modal fade&quot; id=&quot;modalSocio&quot; data-bs-backdrop=&quot;static&quot; data-bs-keyboard=&quot;false&quot; tabindex=&quot;-1&quot; aria-labelledby=&quot;staticBackdropLabel&quot; aria-hidden=&quot;true&quot;&gt;
      &lt;div class=&quot;modal-dialog modal-lg&quot;&gt;
          &lt;div class=&quot;modal-content&quot;&gt;
              &lt;div class=&quot;modal-header&quot;&gt;
                  &lt;h5 class=&quot;modal-title&quot; id=&quot;staticBackdropLabelSocio&quot;&gt;
                      &lt;asp:Label ID=&quot;Label4&quot; runat=&quot;server&quot; CssClass=&quot;text-primary&quot;&gt;&lt;/asp:Label&gt;
                  &lt;/h5&gt;
                 
              &lt;/div&gt;
              
              
              &lt;asp:UpdatePanel ID=&quot;UpdatePanel1&quot;  runat=&quot;server&quot; &gt; 
            
                  &lt;ContentTemplate&gt;
                      &lt;div class=&quot;modal-body&quot;&gt;
                          &lt;div class=&quot;row g-3&quot;&gt;
                                  
                                  
              &lt;div class=&quot;row&quot;&gt;
     &lt;div class=&quot;col-3&quot;&gt;
                  &lt;asp:TextBox ID=&quot;txtBusquedaNombre&quot; runat=&quot;server&quot; CssClass=&quot;form-control&quot; placeholder=&quot;Nombre&quot;&gt;&lt;/asp:TextBox&gt;
         &lt;/div&gt;
                  &lt;div class=&quot;col-3&quot;&gt;
         &lt;asp:TextBox ID=&quot;txtBusquedaApellido&quot; runat=&quot;server&quot; CssClass=&quot;form-control&quot; placeholder=&quot;Apellido&quot;&gt;&lt;/asp:TextBox&gt;
              &lt;/div&gt;
                  &lt;div class=&quot;col-3&quot;&gt;
                  &lt;asp:LinkButton ID=&quot;btnBuscarSocio&quot; runat=&quot;server&quot;  CssClass=&quot;btn btn-outline-success&quot; Text=&quot;Buscar&quot; CausesValidation=&quot;false&quot; ToolTip=&quot;Buscar&quot; OnClick=&quot;btnBuscarSocio_Click&quot; &gt;&lt;span class=&quot;fas fa-search&quot;&gt;&lt;/span&gt;&lt;/asp:LinkButton&gt;
               
              &lt;/div&gt;
                    &lt;/div&gt;
               
                              &lt;div class=&quot;table-responsive mt-3&quot;&gt;
              &lt;asp:GridView ID=&quot;gvSocios&quot; runat=&quot;server&quot; CssClass=&quot;table table-bordered&quot; AutoGenerateColumns=&quot;False&quot;  CellPadding=&quot;4&quot; ForeColor=&quot;#333333&quot; GridLines=&quot;None&quot; OnSelectedIndexChanging=&quot;gvSocios_SelectedIndexChanging&quot;    &gt;
                  &lt;AlternatingRowStyle BackColor=&quot;White&quot; /&gt;
                  &lt;Columns&gt;
                      &lt;asp:BoundField DataField=&quot;Legajo&quot; HeaderText=&quot;Nro. Socio&quot; &gt;&lt;/asp:BoundField&gt;
                      &lt;asp:BoundField DataField=&quot;nombreSocio&quot; HeaderText=&quot;Nombre&quot; /&gt;
                      &lt;asp:BoundField DataField=&quot;Apellido&quot; HeaderText=&quot;Apellido&quot; /&gt;
                      
                     
                      
                  &lt;asp:CommandField ButtonType=&quot;Link&quot;  HeaderText=&quot;Seleccionar&quot;  ShowSelectButton=&quot;True&quot; SelectText=&quot;&lt;i class='fa fa-check-circle'&gt;&lt;/i&gt;&quot;&gt;
                      &lt;ControlStyle CssClass=&quot;btn btn-outline-secondary&quot; /&gt;
                      &lt;/asp:CommandField&gt;
             &lt;/Columns&gt;
                  &lt;EditRowStyle BackColor=&quot;#2461BF&quot; /&gt;
                  &lt;FooterStyle BackColor=&quot;#507CD1&quot; Font-Bold=&quot;True&quot; ForeColor=&quot;White&quot; /&gt;
                  &lt;HeaderStyle BackColor=&quot;#507CD1&quot; Font-Bold=&quot;True&quot; ForeColor=&quot;White&quot; /&gt;
                  &lt;PagerStyle BackColor=&quot;#2461BF&quot; ForeColor=&quot;White&quot; HorizontalAlign=&quot;Center&quot; /&gt;
                  &lt;RowStyle BackColor=&quot;#EFF3FB&quot; /&gt;
                  &lt;SelectedRowStyle BackColor=&quot;#D1DDF1&quot; Font-Bold=&quot;True&quot; ForeColor=&quot;#333333&quot; /&gt;
                  &lt;SortedAscendingCellStyle BackColor=&quot;#F5F7FB&quot; /&gt;
                  &lt;SortedAscendingHeaderStyle BackColor=&quot;#6D95E1&quot; /&gt;
                  &lt;SortedDescendingCellStyle BackColor=&quot;#E9EBEF&quot; /&gt;
                  &lt;SortedDescendingHeaderStyle BackColor=&quot;#4870BE&quot; /&gt;
              &lt;EmptyDataTemplate&gt;
                      &lt;div class=&quot;alert alert-primary&quot; role=&quot;alert&quot;&gt;
                          No se encontraron registros!
                      &lt;/div&gt;                        
                  &lt;/EmptyDataTemplate&gt;
              &lt;/asp:GridView&gt;
                              &lt;/div&gt;
                                     &lt;/div&gt;
                        &lt;/div&gt;
                  &lt;/ContentTemplate&gt;
       
              &lt;/asp:UpdatePanel&gt;
            
              &lt;div class=&quot;modal-footer&quot;&gt;
                      
                                      
                      &lt;asp:Button ID=&quot;BtnCancelarSocio&quot; runat=&quot;server&quot; Text=&quot;Cancelar&quot; CssClass=&quot;btn btn-secondary&quot; OnClick=&quot;btnCancelar_Click&quot; CausesValidation=&quot;False&quot; /&gt;
                  &lt;asp:Button ID=&quot;BtnAgregarSocio&quot; ClientIDMode=&quot;Static&quot; runat=&quot;server&quot;  CausesValidation=&quot;false&quot;  Text=&quot;Seleccionar&quot; CssClass=&quot;btn btn-success&quot; OnClick=&quot;BtnAgregarSocio_Click&quot;  /&gt;
                  
                  &lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  <p>codeBehind:</p>
  <pre><code> protected void BtnAgregarSocio_Click(object sender, EventArgs e)
      {
          TxtSocio.Text = hfidNombreSocio.Value;
      }
  
      
     
      protected void gvSocios_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
      {
          var row = gvFormasPago.Rows[e.NewSelectedIndex];
  
          BtnAgregarSocio.Enabled = true;
              hfSocio.Value = row.Cells[0].Text;
          hfidNombreSocio.Value = row.Cells[0].Text + &quot; - &quot; + row.Cells[1].Text + &quot; &quot; + row.Cells[2].Text;
  
      }
  </code></pre>
  <p>i tried to not use the enabled attribute for test but when the click event fires the hfidNombreSocio value in that moment is empty and the modal never closes.</p>
  <p>maybe i'm not using the update panel right.</p>
  <p>the text box code:</p>
  <pre><code> &lt;div class=&quot;row&quot;&gt;
                   
                     
                      &lt;div class=&quot;col-md-4&quot;&gt;
                      &lt;asp:Label ID=&quot;lblSocio&quot; runat=&quot;server&quot; Visible=&quot;false&quot; Text=&quot;Socio Cuenta Corriente&quot; CssClass=&quot;form-label&quot;&gt;&lt;/asp:Label&gt;
                  &lt;asp:TextBox ID=&quot;TxtSocio&quot; runat=&quot;server&quot; text=&quot;0&quot;  CssClass=&quot;form-control&quot;  &gt;&lt;/asp:TextBox&gt;
               
                          &lt;asp:LinkButton ID=&quot;btnBuscar&quot; runat=&quot;server&quot; Visible=&quot;false&quot;  CssClass=&quot;btn btn-outline-success&quot; Text=&quot;Buscar&quot; CausesValidation=&quot;false&quot; ToolTip=&quot;Buscar&quot; OnClick=&quot;btnBuscar_Click&quot; &gt;&lt;span class=&quot;fas fa-search&quot;&gt;&lt;/span&gt;&lt;/asp:LinkButton&gt;   &lt;%-- this button open the modal  --%&gt;
                     &lt;/div&gt;
              
  </code></pre>