Thursday, January 31, 2008

Using CustomValidator to Validate empty (blank) Textbox

I started my page by using a RequiredFieldValidator, but later found that I needed to validate on more complex criteria as well as if the field is empty. When I added the CustomValidator I found that my code was not firing if the TextBox was empty. After researching this I found that there is a property of the CustomValidator called ValidateEmptyText. The default is false. Once I set this to true it worked and I was able to remove the RequiredFieldValidator.

I'm not sure which version of .Net this property exists in. My page was running on .Net 2.0.

No comments: