Back to Devexpress

RequiredFieldValidationPattern.IsRequired Property

aspnet-devexpress-dot-web-dot-requiredfieldvalidationpattern.md

latest3.5 KB
Original Source

RequiredFieldValidationPattern.IsRequired Property

Gets or sets a value that specifies whether the editor is a required field.

Namespace : DevExpress.Web

Assembly : DevExpress.Web.v25.2.dll

NuGet Package : DevExpress.Web

Declaration

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

Property Value

TypeDefaultDescription
Booleanfalse

true if the editor is a required field; otherwise, false.

|

Remarks

Note

When a grid-based control is in Batch Edit mode, set the Display property to Dynamic , so as not to render the empty space (the validation error element) near the edit cell.

Web Forms:

aspx
...
<dx:GridViewDataComboBoxColumn FieldName="Answer">
    <PropertiesComboBox>
          ...
        <ValidationSettings Display="Dynamic">
            <RequiredField IsRequired="true" />
          </ValidationSettings>
    </PropertiesComboBox>
</dx:GridViewDataComboBoxColumn>
...

MVC:

csharp
settings.CellEditorInitialize = (s, e) => {
    ASPxEdit editor = (ASPxEdit)e.Editor;
    editor.ValidationSettings.Display = Display.Dynamic;
};

Online Example

View Example: How to raise validation on the client

Example

javascript
function OnValidationCompleted(s, e) {
    if(e.isValid && Password.GetValue() != ConfirmedPassword.GetValue()) {
        ConfirmedPassword.SetFocus();
        ErrorMessageNotEqual.SetVisible(true);
        e.isValid = false;
    } else
        ErrorMessageNotEqual.SetVisible(false);
}
aspx
<script runat="server">
     protected void Page_Load(object sender, EventArgs e) {

     }
     protected void ASPxGlobalEvents1_ValidationCompleted(object sender, 
         DevExpress.Web.ValidationCompletedEventArgs e) {
         lErrorMessageNotEqual.ClientVisible 
            = !tbPassword.Value.Equals(tbConfirmedPassword.Value);
     }
</script>
...
         Type password:

         <dxe:ASPxTextBox ID="tbPassword" runat="server" Width="170px" 
         ClientInstanceName="Password" Password="True">
         <ValidationSettings SetFocusOnError="true">
             <RequiredField IsRequired="True" />
         </ValidationSettings>
         </dxe:ASPxTextBox>
         

         Confirm password:
         <dxe:ASPxTextBox ID="tbConfirmedPassword" runat="server" Width="170px" 
          ClientInstanceName="ConfirmedPassword" Password="True">
             <ValidationSettings SetFocusOnError="true">
                 <RequiredField IsRequired="True" />
             </ValidationSettings>
         </dxe:ASPxTextBox>
...

See Also

RequiredFieldValidationPattern Class

RequiredFieldValidationPattern Members

DevExpress.Web Namespace