Edit this page

Validate Treeview by Checked Nodes

By design, the RequiredFieldValidator can validate RadTreeView for a selected node.

This article shows two methods of validating RadTreeView for a checked nodes. In this way, you will be sure that there is at least one checked node of your TreeView.

Using the RequiredFieldValidator

In order this to work, you need to select/unselect the node on its checking/unchecking.

Here is the relevant code:

<telerik:RadTreeView RenderMode="Lightweight" ID="RadTreeView1" runat="server" CheckBoxes="true" OnClientNodeChecked="OnClientNodeCheckedHandler"

<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="RadTreeView1"
    ErrorMessage="Please check at least one node">
function OnClientNodeCheckedHandler(sender, eventArgs) {
    var node = eventArgs.get_node();

Using the CustomValidator

The custom validator will check if the array containing the checked nodes has at least one node.

<telerik:RadTreeView RenderMode="Lightweight" ID="RadTreeView2" runat="server" CheckBoxes="true" Skin="Hay">

<asp:CustomValidator ID="CustomValidator1" runat="server" ClientValidationFunction="validateTreeViewCheckboxes"
    ErrorMessage="Please check at least one node" OnServerValidate="CustomValidator1_ServerValidate">
function validateTreeViewCheckboxes(source, args) {
    var tree = $find("<%= RadTreeView2.ClientID %>");
    args.IsValid = tree.get_checkedNodes().length > 0;
protected void CustomValidator1_ServerValidate(object source, ServerValidateEventArgs args) 
    args.IsValid = RadTreeView2.CheckedNodes.Count > 0; 
Protected Sub CustomValidator1_ServerValidate(ByVal source As Object, ByVal args As ServerValidateEventArgs) Handles CustomValidator1.ServerValidate
    args.IsValid = RadTreeView2.CheckedNodes.Count > 0
End Sub

See Also

Is this article helpful? No Yes
Thank you for your feedback!

Give article feedback

Tell us how we can improve this article