Share via


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.

ASP .NET Compare Validator

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 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:

See Also

Tasks

How to: Add and Configure a CompareValidator Control
How to: Add and Configure a CustomValidator Control
How to: Add and Configure a RangeValidator Control
How to: Add and Configure a RegularExpressionValidator Control
How to: Add and Configure a RequiredFieldValidator Control
How to: Add and Configure a ValidationSummary Control

Concepts

Introduction to the Validation Controls