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

[Solved] Parent node with rtPlus instead of rtMinus

6 Answers 209 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
EPU
Top achievements
Rank 1
EPU asked on 24 Feb 2010, 08:50 PM
Hello,

I'm using a RadTreeView within a master page in sharepoint with ExpandMode = TreeNodeExpandMode.ServerSideCallBack for RadTreeNodes.
When I expand a node with children and then I click on a leaf node, the new page is displayed and the tree is expanded like in the previous page.
But the parent node has a class sets to rtPlus instead of rtMinus with its children displayed.
When I click on the '+' image the children are collapsed.

I think that this can be due to the following code:
private void RenderExpand(HtmlTextWriter writer)  
{  
    if (this.Expanded && (this.ExpandMode != TreeNodeExpandMode.ServerSideCallBack))  
    {  
        writer.AddAttribute(HtmlTextWriterAttribute.Class, "rtMinus");  
    }  
    else  
    {  
        writer.AddAttribute(HtmlTextWriterAttribute.Class, "rtPlus");  
    }  
    writer.RenderBeginTag(HtmlTextWriterTag.Span);  
    writer.RenderEndTag();  
}  
 

Can somebody help me please?

Thanks by advance.

Best regards.

Didier.

6 Answers, 1 is accepted

Sort by
0
Dimitar Milushev
Telerik team
answered on 26 Feb 2010, 02:04 PM
Hello Didier,

Does clicking the Node redirect to a different page? If it postbacks to the same page, do you recreate the TreeView on postback? The expanded state should be properly persisted between postbacks unless you are replacing the Nodes with new ones.

Best wishes,
Dimitar Milushev
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
EPU
Top achievements
Rank 1
answered on 26 Feb 2010, 04:11 PM
Hello,

Thanks for your help.
The TreeView has a datasource. In the first page I expand nodes, then I click on a leaf node.
The new page recreate the treeview.
What do you mean by "The expanded state should be properly persisted between postbacks unless you are replacing the Nodes with new ones."?
Because when the second page is displayed the TreeView is expanded like in the first one, we just have a '+' instead of a '-' in the TreeView for each node previously expanded. The treeView knowns that the node are expanded; when I click on "+" all child nodes collapsed.

It's look like if the displayed imahe '+' is not the correct one, what matches:

    if (this.Expanded && (this.ExpandMode != TreeNodeExpandMode.ServerSideCallBack))  
    {  
        writer.AddAttribute(HtmlTextWriterAttribute.Class, "rtMinus");  
    }  
    else  
    {  
        writer.AddAttribute(HtmlTextWriterAttribute.Class, "rtPlus");  
    }  


Regards.
Didier.

0
Dimitar Milushev
Telerik team
answered on 04 Mar 2010, 10:13 AM
Hello Didier,

If I am understanding you properly, when you click the TreeView you navigate to a different page, e.g. you go from PageA.aspx to PageB.aspx. By default in this scenario RadTreeView will not automatically persist child nodes loaded with ServerSideCallBack between the two pages. This makes me think that when you navigate to the second page, your code adds the child nodes initially when the TreeView is built instead of relying on ServerSideCallBack to load them later. If this is the case, you should set their parent node's ExpandMode to ClientSide when you add the child nodes as you are not using ServerSideCallBack on the second page.

Let me know if my assumptions are wrong. It would also be helpful if you let us see the code that populates the TreeView.

Kind regards,
Dimitar Milushev
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
EPU
Top achievements
Rank 1
answered on 08 Mar 2010, 09:15 AM
Hello,

Since my last answer, due to the huge number of nodes to add in the tree we decided to load all the tree on demand.
We have the same problem when we navigate from page1.aspx to page2.aspx. The tree is not expended after when navigated, even if in the Server's event NodeClick whe can see that the node.Expanded = true and it always have its Nodes filled.
Please find our code:

namespace AtosOrigin.SharePoint.UserControls     
{     
    public class AOTreeNavigation : WebControl, INamingContainer     
    {  
        #region Member variables     
        private RadTreeView _radTreeView;  
        #endregion     
    
        #region Properties   
   
        protected RadTreeView RadTreeView     
        {     
            get      
            {     
                if (_radTreeView == null)     
                {     
                    _radTreeView = CreateTreeView();     
                }     
                return _radTreeView;      
            }     
            set { _radTreeView = value; }     
        }     
    
        /// <summary>     
        /// Contains all root sites url to add inside the tree.     
        /// </summary>     
        [Browsable(false)]     
        public IList<String> SitesServersRelativeUrls     
        {     
            get;     
            set;     
        }  
        #endregion     
    
        #region Events     
        protected void treeView_NodeCreated(object sender, RadTreeNodeEventArgs e)     
        {     
            RadTreeNode node = e.Node;     
            node.ContentCssClass = String.Format("ao-level{0}", node.Level);     
    
            if (node.ExpandMode != TreeNodeExpandMode.ServerSideCallBack)     
            {     
                node.ContentCssClass += " ao-leaf";     
            }     
        }     
    
        protected void treeView_NodeExpand(object sender, RadTreeNodeEventArgs e)     
        {     
            string sNodeWebID = e.Node.Value;     
            SPWeb web= SPContext.Current.Site.AllWebs[new Guid(sNodeWebID)];     
            PublishingWeb pubWeb = PublishingWeb.GetPublishingWeb(web);     
    
            // Add all sub-sites     
            foreach (PublishingWeb curWeb in pubWeb.GetPublishingWebs())     
            {     
                RadTreeNode node = new RadTreeNode(curWeb.Title, curWeb.Web.ID.ToString(),     
                                                   curWeb.Url.Replace(SPContext.Current.Web.Site.Url, string.Empty));     
                if (curWeb.GetPublishingWebs().Count > 0 ||     
                    curWeb.GetPublishingPages().Count > 1)     
                {     
                    node.ExpandMode = TreeNodeExpandMode.ServerSideCallBack;     
                }     
    
                e.Node.Nodes.Add(node);     
            }     
    
            // Add all pages     
            if (pubWeb.GetPublishingPages().Count > 1)     
            {     
                string sDefaultPageServerRelativeUrl = pubWeb.DefaultPage.ServerRelativeUrl;     
                string sWebServerRelativeUrl = pubWeb.Url.Replace(SPContext.Current.Web.Site.Url, string.Empty);     
                foreach (PublishingPage curPage in pubWeb.GetPublishingPages())     
                {     
                    string sCurPageServerRelativeUrl = string.Format("{0}/{1}", sWebServerRelativeUrl,      
                                                                                curPage.Url);     
                    if (!sDefaultPageServerRelativeUrl.Equals(sCurPageServerRelativeUrl,      
                                                                StringComparison.InvariantCultureIgnoreCase))     
                    {     
                        RadTreeNode node = new RadTreeNode(curPage.Title, curPage.ListItem.ID.ToString(),     
                                                            sCurPageServerRelativeUrl);     
                        e.Node.Nodes.Add(node);     
                    }     
                }     
            }     
    
            e.Node.Expanded = true;     
            e.Node.ExpandMode = TreeNodeExpandMode.ClientSide;     
        }  
 
        #endregion     
    
        #region private methods     
        /// <summary>     
        /// Create a Telerik.Web.UI.RadTreeView control and initialize it.     
        /// </summary>     
        /// <returns>A Telerik.Web.UI.RadTreeView control.</returns>     
        private RadTreeView CreateTreeView()     
        {     
            RadTreeView tree = new RadTreeView();     
    
            tree.ID = "RadTreeView";     
            tree.PersistLoadOnDemandNodes = true;     
            tree.EnableViewState = true;     
            tree.ShowLineImages = false;     
            tree.EnableEmbeddedSkins = false;     
            tree.Skin = "AO";     
            tree.OnClientLoad = "OnRadTreeViewLoad";     
            tree.OnClientNodeCollapsing = "OnRadTreeViewNodeCollapsing";     
            tree.OnClientNodeExpanding = "OnRadTreeViewNodeExpanding";     
            tree.NodeCreated += new RadTreeViewEventHandler(treeView_NodeCreated);     
            tree.NodeExpand += new RadTreeViewEventHandler(treeView_NodeExpand);     
    
            return tree;     
        }     
    
        /// <summary>     
        /// Fill all root sites url to add inside the tree.     
        /// </summary>     
        private void FillSitesServersRelativeUrls()     
        {     
            ...     
        }  
        #endregion     
    
        #region Overriden methods     
    
        protected override void CreateChildControls()     
        {     
            FillSitesServersRelativeUrls();     
    
            if (this.Page.IsPostBack == this.Page.IsCallback)     
            {     
                for (int i = 0; i < SitesServersRelativeUrls.Count; i++)     
                {     
                    using (SPSite site = new SPSite(SPContext.Current.Web.Site.Url))     
                    {     
                        SPWeb web = site.OpenWeb(SitesServersRelativeUrls[i])     
                        if (web.Exists)     
                        {     
                            RadTreeNode node = new RadTreeNode(web.Title.ToUpper(CultureInfo.InvariantCulture),     
                                                               web.ID.ToString(), SitesServersRelativeUrls[i]);     
                            if (web.Webs.Count > 0)     
                            {     
                                node.ExpandMode = TreeNodeExpandMode.ServerSideCallBack;     
                            }     
                            this.RadTreeView.Nodes.Add(node);                                 
                        }     
                    }     
                }     
            }     
            this.Controls.Add(this.RadTreeView);     
        }  
        #endregion     
    }     
}    
 

Thanks for your help again.

Best regards.

Didier.
0
Dimitar Milushev
Telerik team
answered on 11 Mar 2010, 03:04 PM
Hi Didier,

The TreeView on Page2 cannot load the 'state' of the TreeView on Page1 - for ASP.NET these are two separate and unrelated controls. When you go to the second page the TreeView is created in its initial state - just like if you opened directly Page2.

There are various approaches in this scenario. For example, if you can detect which nodes should be expanded from the URL of the current page, you can add logic to the CreateChildControls method to add those nodes with ExpandMode.ClientSide and Expanded=true. Another possible approach is use a Query String parameter to send the info about which nodes should be expanded.

Kind regards,
Dimitar Milushev
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
EPU
Top achievements
Rank 1
answered on 16 Mar 2010, 09:24 AM
Hello,

Thanks for your help.
I'll try the first solution.

Regards.
Didier
Tags
TreeView
Asked by
EPU
Top achievements
Rank 1
Answers by
Dimitar Milushev
Telerik team
EPU
Top achievements
Rank 1
Share this question
or