DropDownTree - Validation

  • Politics
  • Sports
  • Events

Isolate this demo as a stand-alone application
  • About this demo
  • C#
  • VB

This example shows how to use the DefaultValue property in a combination with the ASP:RequiredFieldValidator. In this case the page could be submitted only if something, that will change the default value of the control, is chosen from the RadDropDownTree. Keep in mind that the control works with all of the standard ASP.NET validators.

  • DefaultCS.aspx
  • DefaultCS.aspx.cs
  • styles.css
<%@ Page AutoEventWireup="false" CodeFile="DefaultCS.aspx.cs" Inherits="DropDownTree.Examples.Validation.DefaultCS"Language="c#"  %>

<%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns='http://www.w3.org/1999/xhtml'>
<head runat="server">
    <title>Telerik ASP.NET Example</title>
    <link rel="stylesheet" type="text/css" href="styles.css" />
</head>
<body>
    <form id="form1" runat="server">
    <telerik:RadScriptManager runat="server" ID="RadScriptManager1" />
    <telerik:RadSkinManager ID="RadSkinManager1" runat="server" ShowChooser="true" />
    <div class="demo-container">
        <telerik:RadDropDownTree RenderMode="Lightweight" ID="RadDropDownTree1" runat="server" DataSourceID="EntityDataSource1" DefaultMessage="Please select" CheckBoxes="SingleCheck"
            DataTextField="Text" DataFieldID="id" DataValueField="id" DataFieldParentID="parentId" DefaultValue="0" Width="300px"
            OnClientEntryAdded="triggerValidation" OnClientEntryRemoved="triggerValidation">
        </telerik:RadDropDownTree>
        <telerik:RadButton RenderMode="Lightweight" ID="Button1" Text="Submit" runat="server" AutoPostBack="true" OnClick="Button1_Click" ValidationGroup="submit" />
        <br/>
        <asp:CustomValidator runat="server" ClientValidationFunction="validatePage" ValidationGroup="submit" Display="Dynamic"
            CssClass="error-message" ErrorMessage="You need to select a type or a category before submitting the page."></asp:CustomValidator>
        <asp:EntityDataSource runat="server" ID="EntityDataSource1" ConnectionString="name=TelerikReadOnlyEntities"
            DefaultContainerName="TelerikReadOnlyEntities" EntitySetName="Links">
        </asp:EntityDataSource>
        <script type="text/javascript">
            function triggerValidation() {
                Page_ClientValidate();
            }

            function validatePage(sender, args) {
                var dropDownTree = $find("<%=RadDropDownTree1.ClientID%>");

                if (dropDownTree.get_entries().get_count() == 0) {
                    args.IsValid = false;
                }
                else {
                    args.IsValid = true;
                }
            }
        </script>
    </div>
    </form>
</body>
</html>

Support & Learning Resources

Find Assistance

Help Us Improve

Was this example helpful?