get_selectedNode

8 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. 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.
  4. 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.
  5. anushuia
    anushuia avatar
    4 posts
    Member since:
    Aug 2018

    Posted 12 Aug 2018 in reply to Shinu Link to this post

    Hai,

        Here i attached my image of what ever am try with my code am getting error while am follow your code can you help me to solve this?

  6. anushuia
    anushuia avatar
    4 posts
    Member since:
    Aug 2018

    Posted 12 Aug 2018 in reply to Shinu Link to this post

    Hi,

       Here i attach image of what ever am trying with my code, am getting error while try to use your code in side my code can you help me to solve this?

  7. anushuia
    anushuia avatar
    4 posts
    Member since:
    Aug 2018

    Posted 12 Aug 2018 in reply to Shinu Link to this post

    unable display image when am using your code amm getting following two errors.

    can you help me to solve this?

    sender = undefined, args = undefined

    angular.js:14516 TypeError: Cannot read property 'get_selectedNode' of undefined
        at m.$scope.OnClientNodeClicked (filemanagerCtrl.js:146)
        at fn (eval at compile (angular.js:15351), <anonymous>:4:177)
        at e (angular.js:26969)
        at m.$eval (angular.js:18172)
        at m.$apply (angular.js:18272)
        at HTMLDivElement.<anonymous> (angular.js:26974)
        at HTMLDivElement.dispatch (jquery.min.js:3)
        at HTMLDivElement.r.handle (jquery.min.js:3)


  8. Peter Milchev
    Admin
    Peter Milchev avatar
    551 posts

    Posted 14 Aug 2018 Link to this post

    Hello Anushuia,

    The OnClientNodeClicked function is the event handler function for the OnClientNodeClicked of the RadTreeView. When the OnClientNodeClicked event is fired by the TreeView, the TreeView passes itself as the first argument and as a second parameter passes an argument with the get_node() and get_domEvent() methods. 

    The .get_selectedNode() method is a method from the API of the client-side object of the TreeView. You can find more on the client-side API of the TreeView here: 
    Also, I think that reviewing the First Steps with UI for ASP.NET AJAX article and the whole Getting Started section would be helpful to better understanding how our controls work, for example, client-side event handling.

    Regards,
    Peter Milchev
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Back to Top