Home / Community & Support / Knowledge Base / RadControls for ASP.NET and ASP.NET AJAX / General, Installation, Licensing / How-to create a javascript array of all particular RadControls on the page

How-to create a javascript array of all particular RadControls on the page

Article Info

Rating: 5

Article information

Article relates to

 RadControls for ASP.NET AJAX, Q2 2008 and above

Created by

 Veselin Vasilev

Last modified by

 Veselin Vasilev



HOW-TO
Create a method which returns a javascript array containing all RadControls of a particular type (combobox, menu, treeview, etc.)


SOLUTION
This article explains how to create a method which returns an array of all RadTreeView controls on the page.
The same approach could be used to return an array of all RadMenu, RadTextBox, etc. controls on the page.

Here is the javascript method:

function get_allRadTreeViews() 
    var allRadTreeViews = []; 
    var allRadControls = $telerik.radControls; 
     
    for (var i = 0; i < allRadControls.length; i++) 
    { 
        var element = allRadControls[i]; 
         
        if (Telerik.Web.UI.RadTreeView && element instanceof Telerik.Web.UI.RadTreeView) 
        { 
            Array.add(allRadTreeViews, element); 
        } 
    } 
    return allRadTreeViews; 

This method iterates through the built-in radControls array which contains all RadControls on the page and checks the type of every item.

Here is one simple usage of the above method:

function pageLoad() 
    for (var i = 0; i < get_allRadTreeViews().length; i++) 
    { 
        var tree = get_allRadTreeViews()[i]; 
        tree.get_nodes().getNode(0).select(); 
    } 





Comments

If you'd like to comment on this KB article, please, send us a Support Ticket.
Thank you!

Please Sign In to rate this article.