3
Answers

Validation errors count

Dinesh Ambaliya

Dinesh Ambaliya

12y
4.8k
1
How can I count all the validation errors in page when I submit the button
Answers (3)
1
Bhushan Bhure

Bhushan Bhure

NA 392 297.6k 12y

I dont think that you can get that directly as like some control's error count..
 
But you can do one thing, if you just need the count.
 
Put ValidationSummary control on a page.
If there are any errors on Page then Validationsummary control will display all errors as a list.
So in javascript function, get the innerHtml of the validationSummary and get the count of <li>, that will be your error count.

var obj = document.getElementById("ValidationSummary1");
var errorCount = obj.innerHTML.split("<li>").length - 1;
alert('Page is not valid!  ' + errorCount + ' Errors');

Thanks,

Please mark this answer as accepted answer if it resolves your problem.



Accepted
0
Bhushan Bhure

Bhushan Bhure

NA 392 297.6k 12y
You can call it from any event, but I think it's make sense to call on client click event of form Submit button.  So that you can validate the page and let user know the error(s).
0
Dinesh Ambaliya

Dinesh Ambaliya

NA 42 59.7k 12y
your solution worked fine. Thank you.
I putted javascript on button client click event. But is there any other event where I can put this script to count errors.