Creating node not working

2 posts, 0 answers
  1. Drew
    Drew avatar
    5 posts
    Member since:
    Aug 2011

    Posted 15 Jun 2012 Link to this post

    I have created a RadTreeView in a web page.  it is displaying and working properly.  However, I am trying to create a node and add it to the TreeView using the example found at http://demos.telerik.com/aspnet-ajax/treeview/examples/programming/clientsideapi/defaultcs.aspx.  When I do that, it is failing.  The code I am using is:

    function addNode() {
            treeView.trackChanges();
            var node = new Telerik.Web.UI.RadTreeNode();
            node.set_text(FeatureNameText.get_value());
            var parent = treeView.get_selectedNode() || treeView;
            parent.get_nodes().add(node);
            if (parent != treeView && !parent.get_expanded())
                parent.set_expanded(true);
            treeView.commitChanges();
            return false;
        }

    When stepping through the above code, it gets to the node.set_text and throws an exception that says node is null or not an object.  What am I doing wrong here?
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 18 Jun 2012 Link to this post

    Hi Drew,

    Here is the code snippet that worked as expected.

    ASPX:
    <telerik:RadTreeView ID="RadTreeView1" runat="server" CheckBoxes="true">
      <Nodes>
         <telerik:RadTreeNode Text="RadTreeNode1">
         </telerik:RadTreeNode>
         <telerik:RadTreeNode Text="RadTreeNode2">
         </telerik:RadTreeNode>
         <telerik:RadTreeNode Text="RadTreeNode3">
         </telerik:RadTreeNode>
      </Nodes>
    </telerik:RadTreeView>
    <telerik:RadTextBox ID="RadTextBox1" runat="server">
    </telerik:RadTextBox>
    <asp:Button ID="Button1" runat="server" OnClientClick="OnClientClick(); return false;" />

    JS:
    <script type="text/javascript">
        function OnClientClick() {
            var treeView = $find("<%= RadTreeView1.ClientID %>");
            var FeatureNameText = $find("<%= RadTextBox1.ClientID %>");
            treeView.trackChanges();
            var node = new Telerik.Web.UI.RadTreeNode();
            node.set_text(FeatureNameText.get_value());
            var parent = treeView.get_selectedNode() || treeView;
            parent.get_nodes().add(node);
            if (parent != treeView && !parent.get_expanded())
                parent.set_expanded(true);
            treeView.commitChanges();
            return false;
        }
    </script>

    Please provide your full code if it doesn't help.

    Thanks,
    Princy.
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top