ASP.NET Ajax Treeview - multiple nodes expanding on page load

4 posts, 1 answers
  1. Vanessa
    Vanessa  avatar
    3 posts
    Member since:
    Apr 2008

    Posted 16 Jun 2009 Link to this post


    We are using the ASP.NET Ajax Treeview control for our navigation in sharepoint. We have bound the Treeview to the PublishingNavigation:PortalSiteMapDataSource  SiteMapProvider="CombinedNavSiteMapProvider".

    Our problem is that in our navigation a number of links have manually been added to the navigation structure, these links all point to the same page. This means that if you click one of these links you navigate to the actual page BUT on the page loading all nodes that contain any of these extra links are expanded as well as the actual page that we have selected/navigated to.

    Here is the control as implemented in our masterpage:

    <telerik:RadTreeView ID="RadTreeView1"  

    I have set the property SingleExpandPath="True" this works if the client opens a node - all other open nodes close but has no effect on the multiple expanded nodes on page load.

    I have tried to utilize javascript and close all expanded nodes and then only expand the selected node via the OnClientLoad, but this client side event does not fire (I could do this on a button click event and it works, I also called this function via the body onLoad which did not work - nothing happened).

    I then created a code behind file for the masterpage and in the Page_Load used the following function RadTreeview1.CollapseAllNodes(); this did not respond at all, thought the clientid was displayed.


    void Page_Load(object sender, EventArgs e)







    Response.Write("load " + RadTreeview1.ClientID);




    I then found the article 

    Server side events not fired when a Navigation control is bound via SiteMap DataSource

    Fire server-side events when the control is bound to SiteMap DataSource.
    If a Navigation control is bound to a SiteMapDataSource, the NavigateUrl property of the items will be set.
    This effectively disables PostBacks (ItemClick/NodeClick/TabClick events, etc.) because the item navigates
    to the particular URL rather than posting back

    I then tried to follow this example using the following events


    protected void RadTreeview1_OnNodeDataBound(object sender, RadTreeNodeEventArgs e)




    "NavigateUrl"] = e.Node.NavigateUrl;


    e.Node.NavigateUrl =





    protected void RadTreeview1_NodeClick(object sender, Telerik.Web.UI.RadTreeNodeEventArgs e)










    Neither of these events seem to have any effect/do not fire.

    We really need to stop this explosion of the treeview, and only have the selected node xepanded on the page load. Can you please help.


  2. Answer
    Atanas Korchev
    Atanas Korchev avatar
    8462 posts

    Posted 17 Jun 2009 Link to this post

    Hi Vanessa ,

    By default RadTreeView expands all nodes which are bound to the current sitemap node. Since you have more than one link to the same page the treeview expands more than one node.

    I suggest to call the DataBind method of the treeview in Page_Load to force the databinding. Then you can collapse all nodes and expand only one node. If you don't call DataBind the treeview will be bound later than Page_Load and calling any methods in Page_Load will have no effect.

    Also NodeClick is not fired when RadTreeView is bound to sitemap datasource. NodeClick is a postback event and fires only on postbacks. When bound to SiteMapDataSource the nodes have their NavigateUrl property set. This makes the treeview render hyperlinks (<a> tags) which navigate instead of postback.

    I hope this helps,
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. Vanessa
    Vanessa  avatar
    3 posts
    Member since:
    Apr 2008

    Posted 18 Jun 2009 Link to this post

    Thanks Albert

    This resolved the problem, had to add some extra code for if there was no selected node or if the node did not have any parents.

    Here is the completed code placed in the masterpage code behind file for anyone else who has this problem.

    public partial class myClassName : System.Web.UI.MasterPage  
            protected RadTreeView RadTreeView1;  
            /// <summary>  
            /// Handles Page Load Event  
            /// </summary>  
            /// <param name="sender"></param>  
            /// <param name="e"></param>  
            protected void Page_Load(object sender, EventArgs e)  
                if (RadTreeView1.Nodes.Count > 0)  
                if (RadTreeView1.SelectedNode != null)  
                    if (RadTreeView1.SelectedNode.ParentNode != null)  
  4. Varalakshmi
    Varalakshmi avatar
    5 posts
    Member since:
    Mar 2015

    Posted 21 Nov 2015 Link to this post

    hi i had a issue in page load of telerik rad treeview. New child nodes are added to the tree view for the parent but on page load the child nodes are getting cleared, the same issue i had noticed in telerik demo. is there any solution without nodes getting cleared on client side on page load.
Back to Top