I am working with a page and I am getting an Page.IsValid = false and I am trying to determine which control is causing the validation problem.
Failed Validation means that the data in at least one field in the record does not match the required formatting or data reference validations for that field.
A validation error occurs when you have validation/response checking turned on for one of the questions and the respondent fails to answer the question correctly (for numeric formatting , required response).
Credit to Steven for this answer, but I had to make some changes for it to work as this.Validators.Where() had some problems.
using System.Linq; List<IValidator> errored = this.Validators.Cast<IValidator>().Where(v => !v.IsValid).ToList();
In code (page_load), you can do this:
(per MSDN: http://msdn.microsoft.com/en-US/library/dh9ad08f%28v=VS.80%29.aspx)
If (Me.IsPostBack) Then Me.Validate() If (Not Me.IsValid) Then Dim msg As String ' Loop through all validation controls to see which ' generated the error(s). Dim oValidator As IValidator For Each oValidator In Validators If oValidator.IsValid = False Then msg = msg & "<br />" & oValidator.ErrorMessage End If Next Label1.Text = msg End If End If
In the markup, you can...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With