如何在javascript中的gridview内单击按钮时应用文本框空白验证?我有一个gridview,其中包含2个文本框和每行中的一个保存按钮。我想在相应的保存按钮单击时验证文本框。
我已经应用了逻辑,但问题是它只适用于硬编码的文本框 id。如何修改此代码以使其适用于所有 gridview 行?
function gvValidate() {
var grid = document.getElementById('<%= GridViewCTInformation.ClientID %>');
if(grid!=null)
{
var Inputs = grid.getElementsByTagName("input");
for(i = 0; i < 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;
}
}
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