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

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

3 Answers 141 Views
Sharepoint Integration
This is a migrated thread and some comments may be shown as answers.
Vanessa
Top achievements
Rank 1
Vanessa asked on 17 Jun 2009, 03:31 AM
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



3 Answers, 1 is accepted

Sort by
0
Accepted
Atanas Korchev
Telerik team
answered on 17 Jun 2009, 11:38 AM
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.
0
Vanessa
Top achievements
Rank 1
answered on 18 Jun 2009, 06:32 AM
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();  
 
                }  
            }  
        }  
0
Varalakshmi
Top achievements
Rank 1
answered on 21 Nov 2015, 07:26 PM
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.
Tags
Sharepoint Integration
Asked by
Vanessa
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Vanessa
Top achievements
Rank 1
Varalakshmi
Top achievements
Rank 1
Share this question
or