Search for failed asp.net validators

I have a page where I want to log every check message that the user has not met the requirements for the corresponding field.

The problem is that my feedback / button request never arises (possibly due to client checking) and therefore logging never happens before the user actually gets each field on the right (without validation errors).

Button event event method:

protected void btnNext_Click(object sender, EventArgs e) { Page.Validate(); if(Page.IsValid) { //code } else { foreach (IValidator validator in Validators) { if (!validator.IsValid) { PageValidatorErrors error = new PageValidatorErrors { WebsiteID = AppState.WebsiteID, Page = Request.Url.AbsolutePath, URL = Request.Url.ToString(), UserIP = Tools.GetIP(), ErrorMessage = validator.ErrorMessage, CreatedDate = DateTime.Now }; pageValidatorErrorsRep.insert(error); } } } } 

Any ideas how I could record these posts?

Edit:

 <script type="text/javascript"> function validatePage() { if (window.Page_IsValid != true) { //Page_Validators is an array of validation controls in the page. if (window.Page_Validators != undefined && window.Page_Validators != null) { //Looping through the whole validation collection. for (var i = 0; i < window.Page_Validators.length; i++) { window.ValidatorEnable(window.Page_Validators[i]); //if condition to check whether the validation was successfull or not. if (!window.Page_Validators[i].isvalid) { var errMsg = window.Page_Validators[i].getAttribute('ErrorMessage'); alert(errMsg); } } } } } </script> 
+8
c # validation logging
source share
2 answers

Here is part of the solution, you can get validates / true false by calling it on the client side:

http://razeeb.wordpress.com/2009/01/11/calling-aspnet-validators-from-javascript/

 function performCheck() { if(Page_ClientValidate()) { //Do something to log true/ false } } 
+3
source share

Try changing the EnableClientScript property on all validators to false. All your checks will be performed only on the server side.

+2
source share

All Articles