How to: Add and Configure a CustomValidator Control
If the user leaves the targeted control blank, it passes the custom validation test. To force the user to enter a value, add acontrol as well. For details, see .
To validate with a CustomValidator control
Add a CustomValidator control to the form that contains the target control.
Set theproperty to the ID of the control to validate.
Set theproperty to a string to display if the target control fails validation.
If you enter a string into theproperty, the CustomValidator control displays that text when an error occurs. If the property is left empty, the CustomValidator control displays the string defined in the property.
Switch to Design view, and then double-click the CustomValidator control.
Visual Studio opens the code editor with an empty validation method.
Create the handler. For details, see.