Why is it null?

3 posts, 0 answers
  1. Bruno
    Bruno avatar
    11 posts
    Member since:
    Jan 2009

    Posted 16 Sep 2009 Link to this post

    Hi guys,

    I have a tree view and I use a call to Expand only the first level so the user can see the first node expended.

    IE, Safari and Chrome do not see RadTreeView only FF and Opera

    What am I doing wrong here?


    The RadTreeView

    <telerik:RadTreeView ID="RadTreeView" runat="server" OnNodeDataBound="RadTreeView_NodeDataBound"
        OnClientNodeClicked="onClientNodeClickedHandler" OnClientMouseOver="onClientMouseOverHandler"
        CheckBoxes="false" CheckChildNodes="false" MultipleSelect="true" TriStateCheckBoxes="false"
        SingleExpandPath="true" BorderColor="LightGray" BorderWidth="0">

    The call

    $(document).ready(function() {
       // expand until level

       function treeExpandNodes(level) {
          var treeView = $find('<%= RadTreeView.ClientID %>');
          if (treeView != null) {
             var nodes = treeView.get_allNodes();

             for (var i = 0; i < nodes.length; i++) {
                if (nodes[i].get_nodes() != null) {
                   if (nodes[i].get_level() <= level)
             alert('Why is it null?'); // only in FF and Opera this alert is not called!

    image of the output in the 4 browsers

  2. Bruno
    Bruno avatar
    11 posts
    Member since:
    Jan 2009

    Posted 16 Sep 2009 Link to this post

    it will work if I delay the call by 100 ms

          setTimeout(function() { treeExpandNodes(0); }, 100);

    the DOM is already created, should be immediately as I could see the flick of the RadTreeView showing the first node (All Collapsed) and then the expanded until the level I wanted.

  3. DevCraft R3 2016 release webinar banner
  4. Veselin Vasilev
    Veselin Vasilev avatar
    2992 posts

    Posted 17 Sep 2009 Link to this post

    Hi Bruno,

    The document ready state is a little bit early in the page life cycle and the client objects are not yet initialized. That is why it works when a timeout is added.
    The safest way would be to use the pageLoad or the Sys.Application.add_load() method:

    function pageLoad() 

    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.
Back to Top