Skip to main content
Tab

ValidationEventArgs.IsValid Property

Gets or sets a value specifying whether the validated value is valid.

Namespace: DevExpress.Web

Assembly: DevExpress.Web.v24.2.dll

Declaration

public bool IsValid { get; set; }

Property Value

Type Description
Boolean

true if the value is valid; otherwise, false.

Remarks

Use the IsValid property to specify whether the value obtained via the ValidationEventArgs.Value property meets your validation criteria, and can be posted to an editor being validated.

If the entered value is not valid, you can set the IsValid property to false. In this case, the value will not be posted to the editor and a error text specified by the ValidationEventArgs.ErrorText property will be displayed. Or, you can correct the entered value manually by setting the ValidationEventArgs.Value property and leaving the IsValid value set to true. In this case, the corrected value will be written to the editor.

Example

This example demonstrates how to validate editors in a container on the server side. The ASPxEdit.ValidateEditorsInContainer method is used to determine the validity of editors within a callback panel.

View Example

<title>How to validate editors in container </title>

<script type="text/javascript" language="javascript">
    function Validate(s, e) {
        if (ASPxClientEdit.ValidateGroup('testGroup'))
            ClientCallbackPanelDemo.PerformCallback('');
    }
</script>

</head>
<body>
    <form id="form1" runat="server">
    <div>
        <dx:ASPxButton ID="ASPxButtonSave" runat="server" Text="Validate" AutoPostBack="False">
            <ClientSideEvents Click="Validate" />
        </dx:ASPxButton>
        <br />
        <dx:ASPxCallbackPanel ID="ASPxCallbackPanelDemo" runat="server"  HideContentOnCallback="False"
            ClientInstanceName="ClientCallbackPanelDemo" OnCallback="ASPxCallbackPanelDemo_Callback">
            <PanelCollection>
                <dx:PanelContent ID="PanelContent1" runat="server">
                    <table cellspacing="0" cellpadding="4" runat="server" id="serverContainer">
                        <tr>
                            <td style="width: 60px;">
                                <dx:ASPxLabel runat="server" ID="NameLabel" AssociatedControlID="txtNum1" Text="Number 1:" />
                            </td>
                            <td>
                                <dx:ASPxTextBox ID="txtNum1" runat="server" Width="170px" OnValidation="ASPxTextBoxTest_Validation">
                                    <ValidationSettings ValidationGroup="testGroup">
                                        <RequiredField IsRequired="True" ErrorText="Number 1 is required" />
                                    </ValidationSettings>
                                </dx:ASPxTextBox>
                            </td>
                        </tr>
                        <tr>
                            <td style="width: 60px;">
                                <dx:ASPxLabel runat="server" ID="ASPxLabel1" AssociatedControlID="txtNum2" Text="Number 2:" />
                            </td>
                            <td>
                                <dx:ASPxTextBox ID="txtNum2" runat="server" Width="170px" OnValidation="ASPxTextBoxTest_Validation">
                                    <ValidationSettings ValidationGroup="testGroup">
                                        <RequiredField IsRequired="True" ErrorText="Number 2 is required"/>
                                    </ValidationSettings>
                                </dx:ASPxTextBox>
                            </td>
                        </tr>
                    </table>
                </dx:PanelContent>
            </PanelCollection>
        </dx:ASPxCallbackPanel>
    </div>
    </form>
</body>
</html>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DevExpress.Web.ASPxEditors;
using DevExpress.Web.ASPxCallbackPanel;

public partial class _Default : System.Web.UI.Page {

    protected void Page_Init (object sender, EventArgs e) {

    }

    protected void ASPxCallbackPanelDemo_Callback (object sender, DevExpress.Web.CallbackEventArgsBase e) {
        ASPxCallbackPanel callbackPanel = (ASPxCallbackPanel)sender;
        bool isValid = ASPxEdit.ValidateEditorsInContainer(callbackPanel);
    }
    protected void ASPxTextBoxTest_Validation (object sender, ValidationEventArgs e) {
        ASPxTextBox txt = sender as ASPxTextBox;
        int val;
        bool result = Int32.TryParse(txt.Text, out val);
        e.IsValid = result;
        e.ErrorText = "An input value should be a number";
    }
}

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the IsValid property.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

See Also