Telerik
Skip Navigation LinksHome / Community / Forums / SharePoint 2007 (MOSS) > Integrating Controls > ASP.NET Ajax Treeview - multiple nodes expanding on page load

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

Feed from this thread
  • Vanessa avatar

    Posted on Jun 16, 2009 (permalink)

    Hi,

    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"  
       runat="server"
       DataSourceID="ourdatasourcename" 
       Flow="Vertical" 
       EnableEmbeddedSkins="false"
       SkinsPath="~\Telerik\Skins"
       Skin="ourskinname"
       ClickToOpen="true"
       SingleExpandPath="True"
       MultipleSelect="False"
       AutoPostBack="true" 
       ExpandMode="ClientSide"
       ExpandDirection="Down"
       OnClientLoad="On_Load">
       </telerik:RadTreeView>


    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.

    protected

    void Page_Load(object sender, EventArgs e)

     

    {

     

    RadTreeview1.CollapseAllNodes();

     

     

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

     

     

    }


    I then found the article 

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

    http://www.telerik.com/support/kb/aspnet-ajax/menu/server-side-events-not-fired-when-a-navigation-control-is-bound-via-sitemap-datasource.aspx

    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)

     

    {

    e.Node.Attributes[

    "NavigateUrl"] = e.Node.NavigateUrl;

     

    e.Node.NavigateUrl =

    "";

     

    }

     

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

     

    {

     

    Response.Redirect(e.Node.Attributes["NavigateUrl"].ToString());

     

     

     

    }

     

    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.

    Vanessa



    Reply

  • Answer Telerik Admin admin's avatar

    Posted on Jun 17, 2009 (permalink)

    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,
    Albert
    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.

    Reply

  • Vanessa avatar

    Posted on Jun 18, 2009 (permalink)

    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)  
            {  
                RadTreeView1.DataBind();  
                if (RadTreeView1.Nodes.Count > 0)  
                {  
                    RadTreeView1.CollapseAllNodes();  
                }  
     
                if (RadTreeView1.SelectedNode != null)  
                {  
                    if (RadTreeView1.SelectedNode.ParentNode != null)  
                    {  
                        RadTreeView1.SelectedNode.ExpandParentNodes();  
     
                    }  
                }  
            }  

    Reply

Back to Top

Skip Navigation LinksHome / Community / Forums / SharePoint 2007 (MOSS) > Integrating Controls > ASP.NET Ajax Treeview - multiple nodes expanding on page load

Powered by Sitefinity ASP.NET CMS

Contact Us | Site Feedback | Terms of Use | Privacy Policy
Copyright © 2002-2010 Telerik. All rights reserved.