title: How to apply textbox blank validation on button click inside gridview in asp.net using javascript?
body: <p>How to apply textbox blank validation on button click inside gridview in javascript?I have 
  a gridview that contains 2 textboxes and a save button in each row.I want to validate the textboxes on corresponding save button click.</p>
  
  <p>I have applied the logic but problem is that it will only work for textBox ids that are hardcoded.How can I modify this code so that it will work for all the gridview rows?</p>
  
  <pre><code>function gvValidate() {
  
  var grid = document.getElementById('&lt;%= GridViewCTInformation.ClientID %&gt;');
   if(grid!=null) 
    {
     var Inputs = grid.getElementsByTagName("input"); 
      for(i = 0; i &lt; Inputs.length; i++) 
       {
        if(Inputs[i].type == 'text' ) 
         {
             if (Inputs[i].id == 'ctl00_contentPlaceHolderSubScreen_GridViewCTInformation_ctl02_TextBoxCTTermCode') 
               {
                   if (Inputs[i].value == "") {
                       alert("Enter values,blank is not allowed");
                       return false;
                   }
  
               }
               else if (Inputs[i].id == 'ctl00_contentPlaceHolderSubScreen_GridViewCTInformation_ctl02_TextBoxCTTermDesc') {
                   if (Inputs[i].value == "") {
                       alert("Enter values,blank is not allowed");
                       return false;
                   }
               }
  
        }
       }
       return true;
   }
  </code></pre>
  
  <p>}</p>
  
  <pre><code> Protected Sub GridViewTaxInformation_RowDataBound(sender As Object, e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridViewTaxInformation.RowDataBound
      Try
          If e.Row.RowType = DataControlRowType.DataRow Then
  
              Dim btnSave As Button = DirectCast(e.Row.FindControl("ButtonSave"), Button)
              btnSave.Attributes.Add("onclick", "return gvValidate()")
          End If
      Catch ex As Exception
          Common.WriteLog(ex.Message)
          Common.WriteLog((ex.StackTrace))
          Response.Redirect("..\Errors.aspx", False)
      End Try
  End Sub
  </code></pre>