如何在按鈕點擊申請文本框爲空驗證內部在JavaScript GridView的?我有 包含2個文本框,並在每個row.I保存按鈕要驗證相應保存按鈕點擊文本框一個gridview。如何應用文本框空白驗證按鈕點擊asp.net中的gridview內使用javascript?
我已經應用了邏輯,但問題是,它只適用於硬編碼的textBox標識。如何修改此代碼以便它可以用於所有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
你做什麼都行的意思? –
其實我有GridView,其中每行有2個文本框和一個保存按鈕。我想驗證保存按鈕被點擊的特定記錄。 – Priyansh
你爲什麼不使用驗證控制,如:使用RequiredFieldValidator –