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

get_selectedNode

7 Answers 186 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Joseph
Top achievements
Rank 2
Joseph asked on 19 Dec 2011, 06:40 PM
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

7 Answers, 1 is accepted

Sort by
0
Accepted
Kevin
Top achievements
Rank 2
answered on 19 Dec 2011, 09:34 PM
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.
0
Accepted
Shinu
Top achievements
Rank 2
answered on 20 Dec 2011, 06:56 AM
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.
0
Joseph
Top achievements
Rank 2
answered on 20 Dec 2011, 06:10 PM
Thanks for the assistance - that was the issue - my variable declaration was outside of the function.
0
anushuia
Top achievements
Rank 1
answered on 12 Aug 2018, 07:58 AM

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?

0
anushuia
Top achievements
Rank 1
answered on 12 Aug 2018, 08:00 AM

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?

0
anushuia
Top achievements
Rank 1
answered on 12 Aug 2018, 08:07 AM

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)


0
Peter Milchev
Telerik team
answered on 14 Aug 2018, 09:00 AM
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.
Tags
TreeView
Asked by
Joseph
Top achievements
Rank 2
Answers by
Kevin
Top achievements
Rank 2
Shinu
Top achievements
Rank 2
Joseph
Top achievements
Rank 2
anushuia
Top achievements
Rank 1
Peter Milchev
Telerik team
Share this question
or