aspnet-devexpress-dot-web-dot-requiredfieldvalidationpattern.md
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
[DefaultValue(false)]
public bool IsRequired { get; set; }
<DefaultValue(False)>
Public Property IsRequired As Boolean
| Type | Default | Description |
|---|---|---|
| Boolean | false |
true if the editor is a required field; otherwise, false.
|
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:
...
<dx:GridViewDataComboBoxColumn FieldName="Answer">
<PropertiesComboBox>
...
<ValidationSettings Display="Dynamic">
<RequiredField IsRequired="true" />
</ValidationSettings>
</PropertiesComboBox>
</dx:GridViewDataComboBoxColumn>
...
MVC:
settings.CellEditorInitialize = (s, e) => {
ASPxEdit editor = (ASPxEdit)e.Editor;
editor.ValidationSettings.Display = Display.Dynamic;
};
View Example: How to raise validation on the client
function OnValidationCompleted(s, e) {
if(e.isValid && Password.GetValue() != ConfirmedPassword.GetValue()) {
ConfirmedPassword.SetFocus();
ErrorMessageNotEqual.SetVisible(true);
e.isValid = false;
} else
ErrorMessageNotEqual.SetVisible(false);
}
<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