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

Finding a control under a TreeViewNode

3 Answers 149 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Brian Kowald
Top achievements
Rank 1
Brian Kowald asked on 31 Aug 2009, 05:50 PM

Hi. I'm trying to use findControl on a RadTreeNode on the client side to locate a radio button I have in the NodeTemplate, and I can't get it to locate it. I have tried just passing in the ID of the radio button in the code (RB1), and also the full client ID from the generated html. Each time, the control comes up null. 

Also, is there is a way to get the client id of the current node if I have to construct the radio buttons client id?

One more: are there any other ways to access the controls under the node? Use the DOM? Is there a collection of controls availabe?

Thanks,
Brian

        <telerik:RadTreeView ID="RadTreeView1" runat="server" Skin="Office2007"   
             OnClientNodeClicked="RadTreeView1_NodeClick" ShowLineImages="True" > 
            <Nodes> 
                <telerik:RadTreeNode runat="server" Text="Produce">  
                    <NodeTemplate> 
                        <div> 
                            <asp:RadioButton runat="server" ID="RB1" Text="Produce" GroupName="StandardTags" /><br /> 
                        </div> 
                    </NodeTemplate> 
                </telerik:RadTreeNode> 
            </Nodes> 
        </telerik:RadTreeView> 
 

In the js:

function RadTreeView1_NodeClick(sender, eventArgs)  
{  
   var node = eventArgs.get_node();      
   var strControl = "RadTreeView1_i0_RB1";  
   var radio = node.findControl(strControl);  
??? radio is null  
}  
 

3 Answers, 1 is accepted

Sort by
0
Veselin Vasilev
Telerik team
answered on 01 Sep 2009, 03:15 PM
Hello Brian Kowald,

Please use this code:

function RadTreeView1_NodeClick(sender, eventArgs)   
{   
   var node = eventArgs.get_node();  
   var element = node.get_element();       
   var radio = $telerik.findElement(element, "RB1");   


All the best,
Veselin Vasilev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Nicolaï
Top achievements
Rank 2
answered on 30 Nov 2009, 10:23 AM
Hello,

Was struggling with the same thing...
http://www.telerik.com/help/aspnet-ajax/tree_clientradtreenode.html
When I try to use the JS .findControl to find a control inside the node template as the documentation says, I always get "null".

function ClientNodeClicked(sender, eventArgs)
{var node = eventArgs.get_node();    
    alert(node.findControl("contTbl")); <<< "null"
}

This, as you posted, works:
   var element = node.get_element();  
   var contTbl = $telerik.findElement(element, "contTbl"); alert(contTbl);

So, should the documentation be updated?
This one too, maybe: http://www.telerik.com/help/aspnet-ajax/treeview-templates-accessing-controls-inside-templates.html ?

Best regards,
Nicolai


0
Veselin Vasilev
Telerik team
answered on 30 Nov 2009, 10:58 AM
Hello Nicolai,

findControl finds a javascript object (e.g. RadComboBox's javascript object) while findElement finds the DOM element (e.g. <TABLE>).

Kind regards,
Veselin Vasilev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
TreeView
Asked by
Brian Kowald
Top achievements
Rank 1
Answers by
Veselin Vasilev
Telerik team
Nicolaï
Top achievements
Rank 2
Share this question
or