title: How to click on a button that is dynamically generated using JQuery
body: <p>I have got a gridview. Each row has a Alternate Names (TextBox) and a hidden button, this button has to get clicked by JQuery on the textbox "onblur" automatically. </p>
  
  <p><a href="https://i.stack.imgur.com/jI8GD.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/jI8GD.png" alt="enter image description here"></a></p>
  
  <pre><code> &lt;asp:GridView ID="GridView1" CssClass="GridView1" runat="server" AutoGenerateColumns="False" EnableViewState="True"&gt;
          &lt;Columns&gt;
              &lt;asp:TemplateField&gt;
                  &lt;ItemTemplate&gt;
                      &lt;asp:CheckBox ID="checkbox1" runat="server" OnClick="checkboxing(this)" /&gt;
                  &lt;/ItemTemplate&gt;
              &lt;/asp:TemplateField&gt;
              &lt;asp:TemplateField HeaderText="City Name Id"&gt;
                  &lt;ItemTemplate&gt;
                      &lt;asp:Label ID="NameId" runat="server" Text='&lt;%# Eval("Name_Id") %&gt;'&gt;&lt;/asp:Label&gt;
                  &lt;/ItemTemplate&gt;
              &lt;/asp:TemplateField&gt;
              &lt;asp:TemplateField HeaderText="Alternate Names"&gt;
                  &lt;ItemTemplate&gt;
  
                      &lt;asp:TextBox runat="server" ClientIDMode="Static" ID="altTxtNames" Style="display: none" onblur="buttonupdate(this)"&gt;&lt;/asp:TextBox&gt;
                      &lt;asp:Button runat="server" ID="TxtButton" ClientIDMode="Static"  Style="visibility: hidden; display: none" OnClick="TxtButton_Click" /&gt;
                  &lt;/ItemTemplate&gt;
              &lt;/asp:TemplateField&gt;
          &lt;/Columns&gt;
      &lt;/asp:GridView&gt;
  </code></pre>
  
  <p>Whenever "onblur" event occurs in the Alternate Names (textbox) </p>
  
  <pre><code> onblur="buttonupdate(this)"
  </code></pre>
  
  <p>the following JQuery is executed:</p>
  
  <pre><code> function buttonupdate(alternateTxtNames) {
              $('#TxtButton').click();
          }
  </code></pre>
  
  <p>This buttonclick prompts execution of aspx.cs method where the values of edited "Alternate Names" and "City Name Id" from the clicked button grid view row are selected using following code:</p>
  
  <pre><code> protected void TxtButton_Click(object sender, EventArgs e)
              {
                  Button btn = (Button)sender;
                  GridViewRow gvr = (GridViewRow)btn.NamingContainer;
                  string updatedSNo = (gvr.FindControl("NameId") as Label).Text;
                  int SNo = Convert.ToInt32(updatedSNo);
                  string updatedText = (gvr.FindControl("altTxtNames") as TextBox).Text;
             }
  </code></pre>
  
  <p>But everytime the click comes from another row only the <em>first gridview row values</em> are selected which I think is the causality of using <strong>ClientIDMode</strong> because of which it is not able to distinguish the button click from other rows.</p>
  
  <p>How should I overcome this issue. Can someone kindly guide.</p>