<Validate Type="Compare">
The Compare validator checks the target control's value against another control's value or a hard-coded value, using a configurable comparison operator. The classic use case is "make sure the password and confirm-password fields match," but it works equally well for date ranges, type checks, and minimum-value comparisons.
Example
Confirming an email address by comparing two textboxes:
<AddForm>
...
<table>
<tr>
<td>
<Label For="txtEmail" Text="Email" />
<TextBox Id="txtEmail" DataField="Email" DataType="string" />
</td>
</tr>
<tr>
<td>
<Label For="txtEmailConfirm" Text="Confirm Email" />
<TextBox Id="txtEmailConfirm" />
<Validate Type="Compare" Target="txtEmailConfirm" CompareTarget="txtEmail"
Message="The email addresses don't match" />
</td>
</tr>
<tr>
<td colspan="2">
<AddButton Text="Add"/> <CancelButton Text="Cancel"/>
<ValidationSummary />
</td>
</tr>
</table>
</AddForm>Properties
| Property | Values | Default | Description |
|---|---|---|---|
| Type * | Compare | Identifies this as a Compare validator | |
| Target * | control ID | ID of the control to validate | |
| CompareTarget | control ID | ID of the control whose value to compare against. Use either CompareTarget or CompareValue, not both | |
| CompareValue | string | Hard-coded value to compare against. Use either CompareTarget or CompareValue, not both | |
| CssClass | string | CSS class name(s) for styling the validator's error display | |
| DataType | String Integer Double Date Currency | String | The data type used for the comparison |
| Display | Static Dynamic | Dynamic | Whether the validator reserves layout space when no error is shown |
| EnableClientScript | True False | True | When True, validation runs in the browser as well as on the server |
| Height | size | Height of the validator's error display | |
| Message | string | Text shown in the <ValidationSummary> when validation fails | |
| Operator | Equal NotEqual GreaterThan GreaterThanEqual LessThan LessThanEqual DataTypeCheck | Equal | The comparison operator |
| Text | string | Text shown inline at the validator's location when validation fails | |
| Width | size | Width of the validator's error display |
* Required property
Deprecated Properties
These properties use ASP.NET inline styling and are no longer recommended for modern web development. Use the CssClass property to apply CSS classes or the Style property for inline CSS instead.
| Property | Values | Description |
|---|---|---|
| BackColor | color name | #dddddd | Background color of the validator's error display |
| BorderColor | color name | #dddddd | Border color |
| BorderStyle | NotSet None Dotted Dashed Solid Double Groove Ridge Inset Outset | Border style |
| BorderWidth | size | Border width |
| Font-Bold | True False | Bold text |
| Font-Italic | True False | Italic text |
| Font-Names | string | Font family name |
| Font-Overline | True False | Overline text decoration |
| Font-Size | XX-Small X-Small Small Medium Large X-Large XX-Large or size | Font size |
| Font-Strikeout | True False | Strikethrough text decoration |
| Font-Underline | True False | Underline text decoration |
| ForeColor | color name | #dddddd | Text color. Note: the validator hard-codes red, bold text by default. If you set CssClass, XMP automatically clears ForeColor so your stylesheet's color rules take effect |
Property Details
Type: Set to
Compareto identify this as a Compare validator.Target: The
IDof the form control whose value should be checked.CompareTarget: The
IDof a second control whose value the target should be compared with. Use this orCompareValue, not both. Maps to ASP.NET'sControlToCompare.CompareValue: A hard-coded value the target should be compared with (e.g.
CompareValue="18"to require a minimum age). Use this orCompareTarget, not both. Maps to ASP.NET'sValueToCompare.Operator: How the two values are compared. Defaults to
Equal. The special valueDataTypeCheckignores any compare value and instead just verifies that the target control's value can be parsed as the specifiedDataType— useful as a quick "is this a valid number/date?" check without needing a regex.DataType: How the values should be parsed before comparison. Defaults to
String(literal text comparison). Set toInteger,Double,Date, orCurrencyfor type-aware comparisons.Message: The error text shown in the
<ValidationSummary>(if you have one) when validation fails. If no<ValidationSummary>is present, this text appears at the validator's location instead.Text: The text shown inline at the validator's location when validation fails. Used together with
Messageand<ValidationSummary>: a short inline marker (*,**, or an icon) at the validator + the full sentence in the summary block.Display: Whether the validator reserves layout space even when no error is shown.
Dynamic(the default) collapses to no space until validation fails.Staticalways reserves space.EnableClientScript: When
True(the default), the validator runs in the browser before the form is submitted, giving the user immediate feedback. Set toFalseto force server-side-only validation.