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

Alert me if node not choosed

1 Answer 51 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
sudheer
Top achievements
Rank 2
sudheer asked on 26 Jan 2009, 07:00 AM
Hi

I m using radtreeview in a form in which if user doesn't choose any role in treeview it should alert .  In code behind i m able to find using below code
if (Roletreeview.CheckedNodes.Count < 0)
Page.RegisterStartupScript("error", "<script language='JavaScript'>alert('" + Resources.Resources._1010 + "'); return false; </script>");

bit i want alert user using javascript code

Advanced thanks ,if any help

1 Answer, 1 is accepted

Sort by
0
Paul
Telerik team
answered on 26 Jan 2009, 09:51 AM
Hi sudheer,

Please find below a sample code snippet that shows the needed approach.

<form id="form1" runat="server"
<asp:ScriptManager ID="ScriptManager1" runat="server"
</asp:ScriptManager> 
 
<script type="text/javascript"
    function getCheckedNodes() { 
        var treeview = $find('<%= RadTreeView1.ClientID %>'); 
        if (treeview.get_checkedNodes().length == 0) { 
            alert("Please select at least one node"); 
        } 
    } 
</script> 
 
<telerik:RadTreeView ID="RadTreeView1" runat="server" TriStateCheckBoxes="True" CheckBoxes="true" 
    CheckChildNodes="true"
    <Nodes> 
        <telerik:RadTreeNode runat="server" Expanded="True" Text="Root RadTreeNode1"
            <Nodes> 
                <telerik:RadTreeNode runat="server" Text="Child RadTreeNode 1"
                </telerik:RadTreeNode> 
                <telerik:RadTreeNode runat="server" Text="Child RadTreeNode 2"
                </telerik:RadTreeNode> 
            </Nodes> 
        </telerik:RadTreeNode> 
        <telerik:RadTreeNode runat="server" Expanded="True" Text="Root RadTreeNode2"
            <Nodes> 
                <telerik:RadTreeNode runat="server" Text="Child RadTreeNode 1"
                </telerik:RadTreeNode> 
                <telerik:RadTreeNode runat="server" Expanded="True" Text="Child RadTreeNode 2"
                    <Nodes> 
                        <telerik:RadTreeNode runat="server" Text="Child RadTreeNode 1"
                        </telerik:RadTreeNode> 
                        <telerik:RadTreeNode runat="server" Text="Child RadTreeNode 2"
                        </telerik:RadTreeNode> 
                        <telerik:RadTreeNode runat="server" Text="Child RadTreeNode 3"
                        </telerik:RadTreeNode> 
                        <telerik:RadTreeNode runat="server" Text="Child RadTreeNode 4"
                        </telerik:RadTreeNode> 
                    </Nodes> 
                </telerik:RadTreeNode> 
                <telerik:RadTreeNode runat="server" Text="Child RadTreeNode 3"
                </telerik:RadTreeNode> 
                <telerik:RadTreeNode runat="server" Text="Child RadTreeNode 4"
                </telerik:RadTreeNode> 
            </Nodes> 
        </telerik:RadTreeNode> 
        <telerik:RadTreeNode runat="server" Expanded="True" Text="Root RadTreeNode3"
            <Nodes> 
                <telerik:RadTreeNode runat="server" Text="Child RadTreeNode 1"
                </telerik:RadTreeNode> 
                <telerik:RadTreeNode runat="server" Text="Child RadTreeNode 2"
                </telerik:RadTreeNode> 
            </Nodes> 
        </telerik:RadTreeNode> 
    </Nodes> 
</telerik:RadTreeView> 
<input id="Button1" type="button" value="button" onclick="getCheckedNodes()" /></p
</form> 


Sincerely yours,
Paul
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
TreeView
Asked by
sudheer
Top achievements
Rank 2
Answers by
Paul
Telerik team
Share this question
or