Back to Devexpress

ValidationSettings.EnableCustomValidation Property

aspnet-devexpress-dot-web-dot-validationsettings.md

latest4.2 KB
Original Source

ValidationSettings.EnableCustomValidation Property

Gets or sets a value that specifies whether an error frame should be rendered on the client side when you implement a custom validation.

Namespace : DevExpress.Web

Assembly : DevExpress.Web.v25.2.dll

NuGet Package : DevExpress.Web

Declaration

csharp
[DefaultValue(false)]
public bool EnableCustomValidation { get; set; }
vb
<DefaultValue(False)>
Public Property EnableCustomValidation As Boolean

Property Value

TypeDefaultDescription
Booleanfalse

true to render an error frame; otherwise, false.

|

Property Paths

You can access this nested property as listed below:

Object TypePath to EnableCustomValidation
ASPxEdit

.ValidationSettings .EnableCustomValidation

| | EditProperties |

.ValidationSettings .EnableCustomValidation

|

Remarks

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

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

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

Example

The code sample below implements custom validation without using any predefined validation capabilities. Note that you should set the ValidationSettings.EnableCustomValidation property to true to show an error frame.

javascript
function OnAgeValidation(s, e) {
     var age = tbAge.GetText();
     if (age == null || age == "")
          return;
     var digits = "0123456789";
     for (var i = 0; i < age.length; i++) {
          if (digits.indexOf(age.charAt(i)) == -1) {
               tbAge.SetIsValid(false);
               break;
          }
     }
     if (tbAge.GetIsValid() && age.charAt(0) == '0') {
          age = age.replace(/^0+/, "");
          if (age.length == 0)
               age = "0";
          tbAge.SetText(age);

     }
     if (age < 18) {
          tbAge.SetIsValid(false);
          tbAge.SetErrorText('Age must be greater than or equal 18');
     }
}
aspx
<dx:ASPxTextBox ID="ASPxTextBox1" runat="server" Width="170px" ClientInstanceName="tbAge">
     <ValidationSettings ValidateOnLeave="False" EnableCustomValidation="True">
     </ValidationSettings>
</dx:ASPxTextBox>

<dx:ASPxButton ID="btnValidate" runat="server" AutoPostBack="False" Text="Validate">
     <ClientSideEvents Click="OnAgeValidation" />
</dx:ASPxButton>

See Also

Validation Error Message

How to: Implement a Custom Validation

Validation

ValidationSettings Class

ValidationSettings Members

DevExpress.Web Namespace