This problem drove me nuts for a while the other day. I had a CustomValidator on my page that had some client validation code and it was not running. the page just kept validating successfully even though the validation should have failed. The issue was that I had set the ControlToValidate attribute of the validator to one of the form fields on my page, and that field was blank, so the validator thought that it didn't need to run since no value was provided. The field was only required if another field had a certain value, that was the point of the validator. So I couldn't add a RequiredFieldValidator to the control too.
The solution turned out to be just removing the ControlToValidate attribute. That attribute is not required for the CustomValidator. Without that attribute set, the validator runs any time the form is submitted. And you can still display a potential error message next to whichever control you like just by placing the CustomValidator next to that control on the page.
Monday, September 5, 2011
Subscribe to:
Post Comments (Atom)

0 comments:
Post a Comment