get_selectedNode

4 posts, 2 answers
  1. Joseph
    Joseph avatar
    29 posts
    Member since:
    Sep 2007

    Posted 19 Dec 2011 Link to this post

    Hi Telerik Community,

    I am trying to get the text for the selected node, but keep getting "undefined" Here is my javascript:
    var tree = $find("<%= RadTreeView1.ClientID %>");
    var node = tree.get_selectedNode();
    var ParentFolder = tree.get_selectedNode().get_text();

    Right now I just have an alert box to show the value of node and the value of ParentFolder but they both keep coming back "undefined" even when I have a node seleted on my RadTreeView (id=RadTreeView1). I am using version 2011.1.519.35 (not sure if that would make a difference in the syntax).

    Thanks,
    Joe
  2. Answer
    Kevin
    Kevin avatar
    360 posts
    Member since:
    Jul 2012

    Posted 19 Dec 2011 Link to this post

    Hello Joseph,

    Your code looks good. My only question is: When are you calling this code? Is it in a function/ control event or are you calling it when the page loads?

    If you're calling this when the page loads, this is how you should call it:

    function pageLoad() {
        var tree = $find("<%= RadTreeView1.ClientID %>");
        var node = tree.get_selectedNode(); 
        var ParentFolder = tree.get_selectedNode().get_text();
    }

    I hope that helps.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Answer
    Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 20 Dec 2011 Link to this post

    Hello,

    I have tried the same in pageLoad and OnClientNodeClicked event and it worked as expected at my end. Here is the sample code.
    JS:
    <script type="text/javascript">
    function OnClientNodeClicked(sender, args)
     {  
       var txt = sender.get_selectedNode().get_text();
       alert(txt);
     }
    </script>

    -Shinu.
  5. Joseph
    Joseph avatar
    29 posts
    Member since:
    Sep 2007

    Posted 20 Dec 2011 Link to this post

    Thanks for the assistance - that was the issue - my variable declaration was outside of the function.
Back to Top