Skip to main content

ASPxClientEdit.SetIsValid(isValid) Method

Sets a value that specifies whether the editor’s value is valid.

Declaration

SetIsValid(
    isValid: boolean
): void

Parameters

Name Type Description
isValid boolean

True if the editor’s value is valid; otherwise, False.

Remarks

Use the SetIsValid property to manually specify the editor’s validity. When the SetIsValid(false) is called, the error message is shown. Note that this doesn’t mean that the control is declared as invalid for the all subsequent page postbacks. The next time the validation is called, it will be performed again. If the validation indicates that the editor is valid, the postback will occur.

Note

If you want to declare the control as invalid using a custom code, you can use the Validation client-side event handler:

<ClientSideEvents Validation="function(s, e){ e.isValid = false; }" />

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.

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');
     }
}
<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