Validating a custom UserControl via standard validation controls such as RequiredFieldValidator, CustomValidator, etc.
Posted on 2007-08-05
I am a beginner at ASP.NET and have just created my first UserControl which simply contains a drop-down list that is populated from the database. This works well for me since I want to create multiple instances of this functionality.
However, I run into problems when I want to validate my control, on the client side, the way I would validate a standard drop-down list control (one that was not encapsulated in a UserControl). I've considered putting the validator inside my control but I don't want my error message to appear right next to the drop-down list.
The first selection in the drop-down list is always something like "-- Select a Category --" or something like that and I would like to ensure that the user makes a selection other than the first entry with a validator like this:
ErrorMessage="Please select a category."
Is there a way to do something like this which:
1. Allows the validator to live on the same page as the UserControl (not in the user control itself) and
2. Makes validation happen on the client