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

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.

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.


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?

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?

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)
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:
- RadTreeView client-side object API;
- RadTreeNode client-side object API;
- RadTreeNodeCollection client-side object API;
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