Skip to content

<Validate Type="XML">

The XML validator prevents the form from being submitted unless the target control's value can be parsed as well-formed XML. It's a quick well-formedness check (matching tags, balanced quotes, single root element) — it does not validate against any schema or DTD.

Server-side only

This validator runs only on the server. The form must pass all client-side validation and POST back before the XML check happens.

Example

html
<AddForm>
  <SubmitCommand CommandText="INSERT INTO Users(FirstName, LastName, MyXml)
                              VALUES(@FirstName, @LastName, @MyXml)" />
  <table>
    <tr>
      <td>
        <Label For="txtFirstName" Text="First Name" />
        <TextBox Id="txtFirstName" DataField="FirstName" DataType="string" />
      </td>
    </tr>
    <tr>
      <td>
        <Label For="txtXml" Text="Your XML" />
        <TextArea Id="txtXml" DataField="MyXml" DataType="string" />
        <Validate Type="XML" Target="txtXml" Message="Please enter well-formed XML" />
      </td>
    </tr>
    <tr>
      <td colspan="2">
        <AddButton Text="Add" />&nbsp;<CancelButton Text="Cancel" />
        <ValidationSummary />
      </td>
    </tr>
  </table>
</AddForm>

Properties

PropertyValuesDefaultDescription
Type *XMLIdentifies this as an XML 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, the validator participates in the page's client-side validation framework. Note that the actual XML check always runs 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
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 XML to identify this as an XML validator.

  • Target: The ID of the form control whose value should be checked.

  • 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. Static always reserves space.

  • EnableClientScript: Whether the validator participates in the client-side validation framework. The actual XML well-formedness check always runs server-side (XML parsing requires a server-side .NET XmlDocument), so the only practical effect is whether the validator's display is updated client-side after a postback.