Validation Error Message
- 3 minutes to read
You can display an error message when an editor fails validation logic. The ValidationSettings.ErrorDisplayMode property specifies the elements (error text, error image, or error frame) to display within the message.
ErrorDisplayMode property value | Description | Image |
---|---|---|
ImageWithText | An error message displays both an error image and error text. | |
ImageWithTooltip | An error message displays an error image with a tooltip (shown when the mouse pointer hovers over the image). The image tooltip displays the error text. | |
Text | An error message displays error text only. | |
None | The editor displays a frame to indicate an error. |
You can use properties accessed from the ASPxEdit.ValidationSettings property to customize error message elements.
- You can use the ValidationSettings.ErrorFrameStyle property to customize the error frame appearance. Use the ValidationSettings.Display property to specify how the error frame is displayed around the editor.
You can specify error text based on the validation error type.
- The ValidationPattern.ErrorText property allows you to specify the error text displayed if a user does not enter a required editor value. The RequiredFieldValidationPattern.IsRequired property specifies if an editor’s field is required.
- The RegularExpressionValidationPattern.ErrorText property allows you to specify the error text to display if the editor’s specific regular expression (specified by the RegularExpressionValidationPattern.ValidationExpression property) fails validation.
- The MaskSettings.ErrorText property allows you to specify which error text is displayed if user input does not match the mask requirements (specified by the MaskSettings.Mask property).
- The ASPxEdit.ErrorText property allows you to specify the error text to display if an editor’s custom validation fails. See the following help topic to learn more: How to: Implement a Custom Validation.
If you do not specify the error text, the editor uses the ValidationSettings.ErrorText property value instead.
You can also override error text within validation events. To do so, specify the ASPxClientEditValidationEventArgs.errorText parameter of the client-side ASPxClientEdit.Validation event or the ValidationEventArgs.ErrorText parameter of the server-side ASPxEdit.Validation event.
Note
Do any of the following to render an error frame:
- Handle the ASPxClientEdit.Validation or ASPxEdit.Validation event.
- Specify the ValidationSettings.RequiredField or ValidationSettings.RegularExpression property.
- Set the ASPxEdit.IsValid property to false
Otherwise, the editor does not render an error frame on the client side, as this is unnecessary.
However, in some scenarios you may need to validate an editor without using any predefined validation capabilities. In these cases, set the ValidationSettings.EnableCustomValidation property to true to force the editor to render the error frame on the client side.
Note
If an editor’s Native property is set to true, the editor is rendered in native mode using a standard HTML element. In this case, the editor is painted in browser’s native style and its appearance depends upon the browser settings only. So DevExpress style settings (e.g. ValidationSettings.ErrorDisplayMode, ValidationSettings.ErrorFrameStyle , etc.) are not in effect.