TCompareValidator compares the value entered by the user into an input component with the value entered into another input component or a constant value. To specify the input component to validate, set the ControlToValidate property to the ID of the input component.
To compare the associated input component with another input component, set the ControlToCompare property to the ID of the component to compare with.
To compare the associated input component with a constant value, specify the constant value to compare with by setting the ValueToCompare property.
The ValueType property is used to specify the data type of both comparison values. Both values are automatically converted to this data type before the comparison operation is performed. The following value types are supported:
Integer A 32-bit signed integer data type.
Double A double-precision floating point number data type.
Currency A decimal data type that can contain currency symbols.
Date A date data type. The format follows the GNU date syntax.
String A string data type.
Use the Operator property to specify the type of comparison to perform, such as Equal, NotEqual, GreaterThan, GreaterThanEqual, LessThan, LessThanEqual, DataTypeCheck. If you set the Operator property to DataTypeCheck, the TCompareValidator component will ignore the ControlToCompare and ValueToCompare properties and simply indicates whether the value entered into the input component can be converted to the data type specified by the ValueType property.
Namespace: System.Web.UI.WebControls
Properties
ControlToCompare, string, kept in viewstate
Gets or sets the input component to compare with the input control being validated.
ValueToCompare, string, kept in viewstate
Gets or sets a constant value to compare with the value entered by the user into the input component being validated.
ValueType, string, default=String, kept in viewstate
Gets or sets the data type (Integer, Double, Currency, Date, String)
that the values being compared are converted to before the comparison is made.
Operator, string, default=Equal, kept in viewstate
Gets or sets the comparison operation to perform (Equal, NotEqual, GreaterThan, GreaterThanEqual, LessThan, LessThanEqual, DataTypeCheck)
Set the anchor ID for the error message link. If the value is "true" then the ID of the ControlToValidate will be used otherwise the given value will be used as the anchor.
This method overrides the parent's implementation.
The validation succeeds if the input data compares successfully. The validation always succeeds if ControlToValidate is not specified or the input data is empty.