R_Neeman R_Neeman - 24 days ago 8
ASP.NET (C#) Question

Validators array work only first time with asp.net gridview IN GOOGLE CHROME?

Very important!!! I noticed it works perfectly in Internet explorer, and not google chrome!!!

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
if (e.Row.RowType == DataControlRowType.DataRow)
Button saveBtn = (Button)e.Row.FindControl("btnSave");
CompareValidator validatorNow = (CompareValidator)e.Row.FindControl("DateValidator1");

saveBtn.ValidationGroup = "mygroupnow" + e.Row.RowIndex;
validatorNow.ValidationGroup = "mygroupnow" + e.Row.RowIndex;

saveBtn.Attributes.Add("onclick", "AllValidators('"+ e.Row.RowIndex + "');");


I have a gridview with a template, one column has a textbox with validator, and there's a column with a 'save' submit button. I give them a mutual validtionGroup name using their row index. I also have update panel on my page, so until now the only way I could disable/enable a button after validating was with havascript. so I created the following method, to check on client click if the validator is valid:

function AllValidators(index) {
var currentValidationGroup = 'mygroupnow' + index;
for (i = 0; i < Page_Validators.length; i++) {
if (i == index) { if (Page_Validators[i].validationGroup == currentValidationGroup) { ValidatorValidate(Page_Validators[i], currentValidationGroup);
if (Page_Validators[i].isvalid) { alert('Validated!'); } else {alert('not Valid'); } } }

Now, this works great, only for the first index... index 0, when i = 0, then the alerts really go off according to if it is validated or not, but for the other gridview rows, it just always returns 'Validated', even when it is not.. I dont understand whats wrong, the code clearly works since it works the first time, so why not the others too? Please Help, I've been at almost a 1000 questions past week and none answered me exactly to my case.

Thanks in advance!!! (:

and the gridview code :

<asp:GridView ID="GridView1" runat="server" DataSourceID="ds_OpenOrders" OnSelectedIndexChanged="Grid_SelectedIndexChanged"
onrowcreated="GridView1_RowCreated" CssClass="gridBx"
onprerender="GridView1_PreRender" onrowupdated="GridView1_RowUpdated"
onrowupdating="GridView1_RowUpdating" OnRowCommand="GridView1_RowCommand"
onrowdatabound="GridView1_RowDataBound" CellPadding="3" ForeColor="#333333" GridLines="None" AutoGenerateColumns="False" AllowPaging="true" DataKeyNames ="RschEstTime,DRNLoanNumber" PageSize="8" Width="859px" ShowFooter="True">
<AlternatingRowStyle BackColor="White"/>
<asp:TemplateField HeaderText="Est Return Date" SortExpression="RschEstDate" HeaderStyle-VerticalAlign="Top">
<asp:TextBox ID="txtReturnDate1" runat="server" TabIndex="1" Text='<%# Bind("RschEstDate", "{0:MM/dd/yyyy}") %>' Width="70px" AutoPostBack="True" OnTextChanged="GlobalControl_Changed"></asp:TextBox>
<asp:CompareValidator ID="DateValidator1" runat="server" Type="Date" Operator="DataTypeCheck" ErrorMessage="Wrong Format" ControlToValidate="txtReturnDate1" Text="*" Display="Static" EnableClientScript="true"></asp:CompareValidator>
<asp:Button ID="btnSave" runat="server" Text="Save" CommandName="Update" CausesValidation="true" OnClick="MyBtnClick"/>

I've also tried doing simpler action in javascrpt, without the whole loop of Page_validators, and just tried this :

function NextTry(validationName) {
if (Page_ClientValidate(validationName)) { alert('yesss'); } else { alert('noooo'); }


function NextTry(index) {
if(Page_ClientValidate('mygroupnow' + index)) { alert('Valid!');} else { alert('Not Valid'); } }

and again, same problem, it works for the first row, index 0, it alerts really according to that row validation, for the others, it always returns 'Valid', even when not..

Answer Source

I got it working long ago and forgot to close this question.

Thanks for the help everyone!