[Expand]General Information
[Expand]WinForms Controls
[Collapse]ASP.NET Controls and MVC Extensions
 [Expand]Prerequisites
 [Expand]What's Installed
 [Expand]Common Concepts
 [Collapse]ASP.NET WebForms Controls
   Getting Started
  [Expand]Grid View
  [Expand]Tree List
  [Expand]Card View
  [Expand]Reporting
  [Expand]Chart Control
  [Expand]Pivot Grid
  [Expand]Spreadsheet
  [Expand]Rich Text Editor
  [Expand]Scheduler
  [Expand]Site Navigation and Layout
  [Expand]HTML Editor
  [Expand]Gauges
  [Expand]Vertical Grid
  [Collapse]Data Editors
   [Expand]ASPxBinaryImage
   [Expand]Product Information
   [Expand]ASPxButton
   [Collapse]Common Concepts
     Binding to Data
    [Expand]Mask Editing
    [Collapse]Validation
      Validation Overview
      Validation Settings
      Validation Error Message
      Validation Summary
     [Collapse]Examples
       How to: Validate a Particular Editor
       How to: Validate a Group of Editors
       How to: Validate All Editors on a Page
       How to: Implement a Custom Validation
       How to: Determine Editors Validity
    [Expand]List Editors
     Accessibility Support
    ASPxButtonEdit
   [Expand]ASPxCalendar
    ASPxCheckBox
    ASPxCheckBoxList
   [Expand]ASPxColorEdit
   [Expand]ASPxComboBox
   [Expand]ASPxDateEdit
   [Expand]ASPxDropDownEdit
   [Expand]ASPxFilterControl
   [Expand]ASPxHyperLink
    ASPxImage
    ASPxLabel
   [Expand]ASPxListBox
   [Expand]ASPxMemo
   [Expand]ASPxProgressBar
    ASPxRadioButton
   [Expand]ASPxRadioButtonList
   [Expand]ASPxSpinEdit
    ASPxTextBox
    ASPxTimeEdit
   [Expand]ASPxTokenBox
   [Expand]ASPxTrackBar
    ASPxValidationSummary
  [Expand]Docking and Popups
  [Expand]File Management
  [Expand]Data and Image Navigation
  [Expand]Multi-Use Site Controls
  [Expand]Spell Checker
  [Expand]Query Builder
 [Expand]ASP.NET MVC Extensions
 [Expand]Localization
 [Expand]Redistribution and Deployment
  Get More Help
 [Expand]API Reference
[Expand]ASP.NET Bootstrap Controls
[Expand]ASP.NET Core Bootstrap Controls
[Expand]WPF Controls
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Office File API
[Expand]Reporting
[Expand]Report and Dashboard Server
[Expand]Dashboard
[Expand]eXpressApp Framework
[Expand]CodeRush
[Expand]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation

How to: Implement a Custom Validation

To implement a custom validation, you can handle the server-side ASPxEdit.Validation event or the client-side ASPxClientEdit.Validation event. But it is recommended that you perform both the client-side and server-side validations for security reasons.

Within the events, you can test the editor's edit value, which is accessed via the e.Value/e.value (ValidationEventArgs.Value/ASPxClientEditValidationEventArgs.value) property, against custom validation criteria. If the entered value doesn't meet your restrictions, you can specify the editor as invalid by setting the event parameter's e.IsValid/e.isValid (ASPxEdit.IsValid/ASPxClientEditValidationEventArgs.isValid) property to false. Additionally, you can provide a text explaining why the validation has failed by assigning a descriptive text to the e.ErrorText/e.errorText (ValidationEventArgs.ErrorText/ASPxClientEditValidationEventArgs.errorText) property. When an editor is invalid, the specified text will be displayed within a specific message box.

The code sample below demonstrates how you can perform custom client-side validation to limit an permissible user age. For this purpose, the ASPxClientEdit.Validate event is handled.

Note

An error frame is automatically rendered on the client side in the following situations.

Otherwise the error frame is not rendered to the client side as being unnecessary.

However, in some scenarios you need to perform the editor's validation fully by yourself without using any of the predefined validation capabilities. In these cases, set the ValidationSettings.EnableCustomValidation property to true to force the editor to render the error frame to the client side.

The code sample below demonstrates how you can perform a custom validation without using any predefined validation capabilities. Note that in this case, the ValidationSettings.EnableCustomValidation property should be set to true to show an error frame.

Is this topic helpful?​​​​​​​