ASP.NET CompareValidator Control
Definition and Usage
The CompareValidator control is used to compare the value of one input control with the value of another input control or a constant value.
Note: If the input control is empty, no validation functions are called, and validation will succeed. Use the RequiredFieldValidator control to make the field required (mandatory).
Properties
| Property | Description |
|---|---|
| BackColor | The background color of the CompareValidator control. |
| ControlToCompare | The name of the control to compare with the control being validated. |
| ControlToValidate | The ID of the control to validate. |
| Display | The display behavior of the validation control. Legal values are: None - The control does not display. Used only for displaying error messages in the ValidationSummary control.<br> Static - The control displays the error message if validation fails. Space for the message is reserved on the page even if the input passes validation.<br> Dynamic - The control displays the error message if validation fails. Space for the message is dynamically added to the page if the input passes validation. |
| EnableClientScript | A Boolean value that specifies whether client-side validation is enabled. |
| Enabled | A Boolean value that specifies whether the validation control is enabled. |
| ErrorMessage | The text displayed in the ValidationSummary control when validation fails. Note: If the Text property is not set, this text is also displayed in the validation control. |
| ForeColor | The foreground color of the control. |
| id | The unique ID of the control. |
| IsValid | A Boolean value that indicates whether the control specified by ControlToValidate passed validation. |
| Operator | The type of comparison operation to perform. Operators include: Equal<br> GreaterThan<br> GreaterThanEqual<br> LessThan<br> LessThanEqual<br> NotEqual<br> DataTypeCheck |
| runat | Specifies that the control is a server control. Must be set to "server". |
| Text | The message displayed when validation fails. |
| Type | Specifies the data type of the values to compare. Types include: Currency<br> Date<br> Double<br> Integer<br> String |
| ValueToCompare | A constant value to compare with the value entered by the user in the input control being validated. |