Skip to content

<Validate Type="Required">

The Required validator prevents the form from being submitted if its target control is empty. It's the most commonly used validator — drop it next to any control that the user must fill in.

Not for checkboxes

A <CheckBox> always has a value (checked or unchecked), and a <CheckBoxList> is treated similarly — so Type="Required" doesn't do what you'd expect on those. Use <Validate Type="Checkbox"> to require a single checkbox to be checked, or <Validate Type="CheckboxList"> to require at least one item in a list to be selected.

Example

html
<AddForm>
  <SubmitCommand CommandText="INSERT INTO Users(FirstName, LastName) VALUES(@FirstName, @LastName)" />
  <table>
    <tr>
      <td>
        <Label For="txtFirstName" Text="First Name" />
        <TextBox Id="txtFirstName" DataField="FirstName" DataType="string" />
        <Validate Type="Required" Target="txtFirstName"
                  Message="You must enter a First Name" />
      </td>
    </tr>
    <tr>
      <td>
        <Label For="txtLastName" Text="Last Name" />
        <TextBox Id="txtLastName" DataField="LastName" DataType="string" />
      </td>
    </tr>
    <tr>
      <td colspan="2">
        <AddButton Text="Add" />&nbsp;<CancelButton Text="Cancel" />
        <ValidationSummary />
      </td>
    </tr>
  </table>
</AddForm>

Properties

PropertyValuesDefaultDescription
Type *RequiredIdentifies this as a Required validator
Target *control IDID of the control to validate
CssClassstringCSS class name(s) for styling the validator's error display
DisplayStatic DynamicDynamicWhether the validator reserves layout space when no error is shown
EnableClientScriptTrue FalseTrueWhen True, validation runs in the browser as well as on the server
HeightsizeHeight of the validator's error display
MessagestringText shown in the <ValidationSummary> when validation fails
TextstringText shown inline at the validator's location when validation fails. Often a short marker (e.g. * or **)
WidthsizeWidth 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.

PropertyValuesDescription
BackColorcolor name | #ddddddBackground color of the validator's error display
BorderColorcolor name | #ddddddBorder color
BorderStyleNotSet None Dotted Dashed Solid Double Groove Ridge Inset OutsetBorder style
BorderWidthsizeBorder width
Font-BoldTrue FalseBold text
Font-ItalicTrue FalseItalic text
Font-NamesstringFont family name
Font-OverlineTrue FalseOverline text decoration
Font-SizeXX-Small X-Small Small Medium Large X-Large XX-Large or sizeFont size
Font-StrikeoutTrue FalseStrikethrough text decoration
Font-UnderlineTrue FalseUnderline text decoration
ForeColorcolor name | #ddddddText 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 Required to identify this as a Required validator. The single <Validate> tag supports many validator types via this attribute (see Compare, Range, Email, RegEx, and others).

  • Target: The ID of the form control whose value should be checked. Maps to ASP.NET's ControlToValidate.

  • 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 Message and <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 — usually what you want. Static always reserves space (useful when you want the form layout to not shift when an error appears).

  • EnableClientScript: When True (the default), the validator runs in the browser before the form is submitted, giving the user immediate feedback. Set to False to force server-side-only validation — useful for controls (like rich text editors) that don't expose their value cleanly to client-side script.