Sometimes when a page loads you’ll want the user to be able to see the which fields are required. This is normally done by presenting an asterisk next to the fields that need to be populated/selected.
The RequiredFieldValidator does not automatically perform validation upon load, but here’s some code that will allow you to do so:
I usually put this in the OnPreRender event handler as at that point everything is done processing on the page.
foreach (IValidator validator in Validators) { if (validator is RequiredFieldValidator) { validator.Validate(); } }
This will ensure that the page’s required field validators are validated when the page loads. Therefore giving the user the insight into the required fields.
Leave a Reply
You must be logged in to post a comment.