Introduction to the CompareValidator Control
The CompareValidator control validates data values in the SelectionList or TextBox control. Set the CompareValidator control's ControlToValidate property to the name of the SelectionList or TextBox control to validate.
Your application can use the CompareValidator control to compare the data value entered by the user to a value in another control. To do so, set the ControlToCompare property to the string in the ID property of the SelectionList or TextBox control that contains the comparison value.
Alternatively, your application can use the CompareValidator control to compare a SelectionList or TextBox control's data value to a literal value that you specify at design time. To compare the control's data value to a literal value, set the CompareValidator control's ValueToCompare property in the Properties window to the literal comparison value.
Whether your application compares a control's data value to the value in another control or to a literal value, you must specify the data type of the values being compared. Set the data type by using the CompareValidator control's Type property.
When you add a CompareValidator control to a container control or template:
- The ErrorMessage property is set to CompareValidator.
- The StyleReference property is set to error, which maps to a predefined style by default.
Adding and Configuring a CompareValidator Control | CompareValidator Control | CompareValidator Class | Introduction to the Validation Controls | Validating Against a Specific Value for Web Server Controls