title: How to get value of textbox inside of gridview
body: <p>My <code>GridView</code> has a <code>ContentTemplate</code> containing <code>ItemTemplate</code>. 
  <code>ItemTemplate</code> has <code>textbox</code> and <code>button</code>. </p>
  
  <p>Here is a fragment of the code:</p>
  
  <pre><code>     &lt;asp:TemplateField HeaderText="Email"&gt;  
        &lt;ItemTemplate&gt;
           &lt;asp:TextBox runat="server" ID="txtEmail" Text='&lt;%#Eval("CustEmail") %&gt;' /&gt;
                &lt;asp:Button id="btnUpdate" Text="Update Email" ButtonType="Button" CommandName="UpdateEmail" 
                 Visible="true" runat="server"
                 OnClientClick="return ValidateEmail(this)" /&gt;
  
           &lt;/ItemTemplate&gt;
       &lt;/asp:TemplateField&gt;
  </code></pre>
  
  <p>What I'm doing is calling <code>ValidateEmail()</code> method to validate my email field. For this I need to get email field value to validate it.</p>
  
  <p>This is my <code>ValidateEmail()</code> method:</p>
  
  <pre><code>        function ValidateEmail(btnObj)
          {
  
          alert(btnObj.id);
          var email = $(btnObj).closest('input').attr('id');
          alert(email)
          return false;
      }
  </code></pre>
  
  <p>I'm able to get <code>id</code> for my button which is <code>MainContent_GridView1_btnUpdate_0</code></p>
  
  <p>This is my rendered html for the GridView:</p>
  
  <pre><code>&lt;div&gt;
  &lt;table cellspacing="0" id="MainContent_GridView1" style="border-collapse:collapse;"&gt;
      &lt;tr&gt;
          &lt;th scope="col"&gt;&lt;a href="javascript:__doPostBack(&amp;#39;ctl00$MainContent$GridView1&amp;#39;,&amp;#39;Sort$CustID&amp;#39;)"&gt;Customer ID&lt;/a&gt;&lt;/th&gt;&lt;th scope="col"&gt;&lt;a href="javascript:__doPostBack(&amp;#39;ctl00$MainContent$GridView1&amp;#39;,&amp;#39;Sort$CustFirstName&amp;#39;)"&gt;First Name&lt;/a&gt;&lt;/th&gt;&lt;th scope="col"&gt;&lt;a href="javascript:__doPostBack(&amp;#39;ctl00$MainContent$GridView1&amp;#39;,&amp;#39;Sort$CustLastName&amp;#39;)"&gt;Last Name&lt;/a&gt;&lt;/th&gt;&lt;th scope="col"&gt;&lt;a href="javascript:__doPostBack(&amp;#39;ctl00$MainContent$GridView1&amp;#39;,&amp;#39;Sort$CustCity&amp;#39;)"&gt;City&lt;/a&gt;&lt;/th&gt;&lt;th scope="col"&gt;Email&lt;/th&gt;
      &lt;/tr&gt;&lt;tr&gt;
          &lt;td&gt;
            &lt;span id="MainContent_GridView1_lblCustID_0"&gt;12&lt;/span&gt;
          &lt;/td&gt;&lt;td&gt;
            &lt;span id="MainContent_GridView1_lblFirstName_0"&gt;Anders&lt;/span&gt;
          &lt;/td&gt;&lt;td&gt;
            &lt;span id="MainContent_GridView1_lblLastName_0"&gt;Rohansen&lt;/span&gt;
          &lt;/td&gt;&lt;td&gt;
           &lt;span id="MainContent_GridView1_lblCity_0"&gt;Takoma Park&lt;/span&gt;
         &lt;/td&gt;&lt;td&gt;
           &lt;input name="ctl00$MainContent$GridView1$ctl02$txtEmail" type="text" value="a.rohansen@testemail.com" id="MainContent_GridView1_txtEmail_0" /&gt;
            &lt;span data-val-controltovalidate="MainContent_GridView1_txtEmail_0" data-val-errormessage="Must enter Email Address" data-val-validationGroup="grpEmail" id="MainContent_GridView1_ctl00_0" data-val="true" data-val-evaluationfunction="RequiredFieldValidatorEvaluateIsValid" data-val-initialvalue="" style="visibility:hidden;"&gt;Must enter Email Address&lt;/span&gt;
             &lt;input type="submit" name="ctl00$MainContent$GridView1$ctl02$btnUpdate" value="Update Email" onclick="return ValidateEmail(this);WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(&amp;quot;ctl00$MainContent$GridView1$ctl02$btnUpdate&amp;quot;, &amp;quot;&amp;quot;, true, &amp;quot;grpEmail&amp;quot;, &amp;quot;&amp;quot;, false, false))" id="MainContent_GridView1_btnUpdate_0" ButtonType="Button" /&gt;
  
           &lt;/td&gt;
      &lt;/tr&gt;&lt;tr style="background-color:#EEEEEE;"&gt;
          &lt;td&gt;
            &lt;span id="MainContent_GridView1_lblCustID_1"&gt;8&lt;/span&gt;
          &lt;/td&gt;&lt;td&gt;
            &lt;span id="MainContent_GridView1_lblFirstName_1"&gt;Deborah&lt;/span&gt;
          &lt;/td&gt;&lt;td&gt;
            &lt;span id="MainContent_GridView1_lblLastName_1"&gt;Damien&lt;/span&gt;
          &lt;/td&gt;&lt;td&gt;
           &lt;span id="MainContent_GridView1_lblCity_1"&gt;Fresno&lt;/span&gt;
         &lt;/td&gt;&lt;td&gt;
           &lt;input name="ctl00$MainContent$GridView1$ctl03$txtEmail" type="text" value="d.damien@testemail.com" id="MainContent_GridView1_txtEmail_1" /&gt;
            &lt;span data-val-controltovalidate="MainContent_GridView1_txtEmail_1" data-val-errormessage="Must enter Email Address" data-val-validationGroup="grpEmail" id="MainContent_GridView1_ctl00_1" data-val="true" data-val-evaluationfunction="RequiredFieldValidatorEvaluateIsValid" data-val-initialvalue="" style="visibility:hidden;"&gt;Must enter Email Address&lt;/span&gt;
             &lt;input type="submit" name="ctl00$MainContent$GridView1$ctl03$btnUpdate" value="Update Email" onclick="return ValidateEmail(this);WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(&amp;quot;ctl00$MainContent$GridView1$ctl03$btnUpdate&amp;quot;, &amp;quot;&amp;quot;, true, &amp;quot;grpEmail&amp;quot;, &amp;quot;&amp;quot;, false, false))" id="MainContent_GridView1_btnUpdate_1" ButtonType="Button" /&gt;
  
           &lt;/td&gt;
      &lt;/tr&gt;&lt;tr&gt;
          &lt;td&gt;
            &lt;span id="MainContent_GridView1_lblCustID_2"&gt;7&lt;/span&gt;
          &lt;/td&gt;&lt;td&gt;
            &lt;span id="MainContent_GridView1_lblFirstName_2"&gt;Derek&lt;/span&gt;
          &lt;/td&gt;&lt;td&gt;
            &lt;span id="MainContent_GridView1_lblLastName_2"&gt;Chaddick&lt;/span&gt;
          &lt;/td&gt;&lt;td&gt;
           &lt;span id="MainContent_GridView1_lblCity_2"&gt;Fairfield&lt;/span&gt;
         &lt;/td&gt;&lt;td&gt;
           &lt;input name="ctl00$MainContent$GridView1$ctl04$txtEmail" type="text" value="d.chaddick@testemail.com" id="MainContent_GridView1_txtEmail_2" /&gt;
            &lt;span data-val-controltovalidate="MainContent_GridView1_txtEmail_2" data-val-errormessage="Must enter Email Address" data-val-validationGroup="grpEmail" id="MainContent_GridView1_ctl00_2" data-val="true" data-val-evaluationfunction="RequiredFieldValidatorEvaluateIsValid" data-val-initialvalue="" style="visibility:hidden;"&gt;Must enter Email Address&lt;/span&gt;
             &lt;input type="submit" name="ctl00$MainContent$GridView1$ctl04$btnUpdate" value="Update Email" onclick="return ValidateEmail(this);WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(&amp;quot;ctl00$MainContent$GridView1$ctl04$btnUpdate&amp;quot;, &amp;quot;&amp;quot;, true, &amp;quot;grpEmail&amp;quot;, &amp;quot;&amp;quot;, false, false))" id="MainContent_GridView1_btnUpdate_2" ButtonType="Button" /&gt;
  
           &lt;/td&gt;
      &lt;/tr&gt;
  &lt;/table&gt;
   &lt;/div&gt;
  </code></pre>
  
  <p>How can I get the id for email text box?</p>
  
  <p>Thank you</p>