Back to Devexpress

How to: Validate Edit Form Template Container

aspnet-4693-components-tree-list-examples-how-to-validate-edit-form-template-container.md

latest3.6 KB
Original Source

How to: Validate Edit Form Template Container

  • Dec 17, 2020

This example shows how to validate custom editors, contained within the Edit Form Template Container, on the client. In this sample, we use the ASPxClientEdit.ValidateGroup method to perform client-side validation of editors that belong to the “EditForm” validation group.

aspx
<script type="text/javascript">
    function OnUpdateClick(editor) {
        if(ASPxClientEdit.ValidateGroup("EditForm"))
            treeList.UpdateEdit();
    }
</script>
<dx:ASPxTreeList ID="ASPxTreeList2" runat="server" AutoGenerateColumns="False"
    DataSourceID="AccessDataSource1" KeyFieldName="ID"
    ParentFieldName="ParentID" ClientInstanceName="treeList">
    <Templates>
        <EditForm>
        <table style="width: 100%">
            <tr>
                <td>Department:</td>
                <td><dx:ASPxTextBox ID="ASPxTextBox1" runat="server"
                        Value='<%# Bind("Department") %>'
                Width="170px">
                    <ValidationSettings ValidationGroup="EditForm">
                    </ValidationSettings>
            </dx:ASPxTextBox></td>
            </tr>
            <tr>
                <td>Location:</td>
                <td><dx:ASPxTextBox ID="ASPxTextBox2" runat="server"
                       Value='<%# Bind("Location") %>'
                Width="170px">
                    <ValidationSettings ValidationGroup="EditForm">
                    </ValidationSettings>
            </dx:ASPxTextBox></td>
            </tr>
            <tr>
                <td>Budget:</td>
                <td><dx:ASPxSpinEdit ID="ASPxSpinEdit1" runat="server" Height="21px" Number="0"
                           Value='<%# Bind("Budget") %>'>
                    <ValidationSettings ValidationGroup="EditForm">
                    </ValidationSettings>
            </dx:ASPxSpinEdit></td>
            </tr>
            <tr>
                <td>Phone:</td>
                <td><dx:ASPxTextBox ID="ASPxTextBox3" runat="server"
                       Value='<%# Bind("Phone") %>' Width="170px">
           <ValidationSettings ValidationGroup="EditForm">
            <RegularExpression ErrorText="Wrong phone number"
             ValidationExpression="((\(\d{3}\) ?)|(\d{3}-))?\d{3}-\d{4}" />
           </ValidationSettings>
            </dx:ASPxTextBox></td>
            </tr>
            <tr>
                <td colspan="2">
                    <a href="javascript:void(0);" onclick="OnUpdateClick(this)">Update</a>
                    <dx:ASPxTreeListEditFormTemplateReplacement runat="server"
                     Type="CancelButton"/>
                </td>
            </tr>
        </table>
        </EditForm>
    </Templates>
    <Columns>
        <dx:TreeListTextColumn FieldName="Department" VisibleIndex="0">
        </dx:TreeListTextColumn>
        <dx:TreeListTextColumn FieldName="Budget" VisibleIndex="1">
        </dx:TreeListTextColumn>
        <dx:TreeListTextColumn FieldName="Location" VisibleIndex="2">
        </dx:TreeListTextColumn>
        <dx:TreeListTextColumn FieldName="Phone" VisibleIndex="3">
        </dx:TreeListTextColumn>
        <dx:TreeListCommandColumn VisibleIndex="4">
            <EditButton Visible="True">
            </EditButton>
        </dx:TreeListCommandColumn>
    </Columns>
    <SettingsEditing Mode="EditForm" />
</dx:ASPxTreeList>

To learn more, see Node Validation and Error Indication.