This is a migrated thread and some comments may be shown as answers.

Treeview validation

4 Answers 213 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Ivan Queiroz
Top achievements
Rank 1
Ivan Queiroz asked on 27 Apr 2010, 04:54 PM
This should be pretty straightforward, but for some reason, I cannot get treeview to validate properly: the required field validator fails to see when a node is checked, even if ALL nodes are checked. This is a sample code:

    <asp:ValidationSummary ID="ValidationSummary1" runat="server" HeaderText="Please review the following errors:" ShowMessageBox="True" ShowSummary="false" DisplayMode="BulletList" /> 
 
    <telerik:RadTreeView ID="RadTreeViewStates" runat="server" CheckBoxes="true" CheckChildNodes="true" TriStateCheckBoxes="true" LoadingMessage="Loading states" Skin="Office2007"
        <Nodes> 
            <telerik:RadTreeNode Checkable="true" Text="All States" Expanded="true"
                <Nodes> 
                    <telerik:RadTreeNode Checkable="true" Text="Northeast"
                        <Nodes> 
                            <telerik:RadTreeNode Checkable="true" Text="CT" Value="CT"></telerik:RadTreeNode> 
                            <telerik:RadTreeNode Checkable="true" Text="MA" Value="MA"></telerik:RadTreeNode> 
                            <telerik:RadTreeNode Checkable="true" Text="ME" Value="CT"></telerik:RadTreeNode> 
                            <telerik:RadTreeNode Checkable="true" Text="NH" Value="CT"></telerik:RadTreeNode> 
                            <telerik:RadTreeNode Checkable="true" Text="NY" Value="CT"></telerik:RadTreeNode> 
                            <telerik:RadTreeNode Checkable="true" Text="PA" Value="CT"></telerik:RadTreeNode> 
                            <telerik:RadTreeNode Checkable="true" Text="RI" Value="CT"></telerik:RadTreeNode> 
                            <telerik:RadTreeNode Checkable="true" Text="VT" Value="CT"></telerik:RadTreeNode> 
                        </Nodes> 
                    </telerik:RadTreeNode>                   
                </Nodes> 
            </telerik:RadTreeNode> 
        </Nodes> 
    </telerik:RadTreeView> 
 
    <asp:RequiredFieldValidator ID="rvRadTreeViewStates" runat="server" ErrorMessage="Please select at least one state" Display="Dynamic" ControlToValidate="RadTreeViewStates">*</asp:RequiredFieldValidator> 
 
    <asp:Button ID="ButtonSaveSearch" runat="server" Text="Save"  /> 
 

The above is similar to the Validation Selection demo. Am I missing something?

Thanks,

Ivan

4 Answers, 1 is accepted

Sort by
0
Accepted
Yana
Telerik team
answered on 29 Apr 2010, 08:57 AM
Hi Ivan,

By default RequiredFieldValidator validates whether a node is selected. This help article explains how you can validate by checked nodes.

Best wishes,
Yana
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Accepted
Shinu
Top achievements
Rank 2
answered on 29 Apr 2010, 08:59 AM

Hi Ivan,

The behaviour is expected since the RadTreeViewStates.SelectedValue will be "null" evenif there is some nodes checked. So one suggestion would be selecting/unselecting the node whenever checkbox is checked/unchecked. You can perform this from client side.

JavaScript:

 
<script type="text/javascript">  
    function OnClientNodeChecked(sender, args) {  
        var node = args.get_node()  
        node.set_selected(node.get_checked());  
    }  
</script> 

[Attach the OnClientNodeChecked event to RadTreeView]

-Shinu.

0
Michael Love
Top achievements
Rank 1
answered on 25 Jun 2010, 06:10 PM
So, I really don't want to have to "select" my tree row. Are there other options?

Mike
0
Michael Love
Top achievements
Rank 1
answered on 25 Jun 2010, 07:44 PM
Actually, I looked at the link provided and used a Custom validator.

Thanks, Mike
Tags
TreeView
Asked by
Ivan Queiroz
Top achievements
Rank 1
Answers by
Yana
Telerik team
Shinu
Top achievements
Rank 2
Michael Love
Top achievements
Rank 1
Share this question
or