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

ExpandMode Property When Building Tree Programmatically

2 Answers 90 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Jeff
Top achievements
Rank 1
Jeff asked on 03 Feb 2010, 12:54 AM
Hello,

I'm trying to build a RadTreeView control programmatically (as part of a CompositeControl). I'm getting the ICallbackEventHandler error when I try to expand the node (ServerSideCallBack mode).

I first tried this on an ASPX page and it's working fine. When I migrated the code to the CompositeControl, I was no longer able to set the ExpandMode property at the TreeView level, only at the node level.

ScriptManager is registered. I implemented ICallbackEventHandler and  INamingContainer (which wasn't necessary in the ASPX version).

I'm not sure what else to do.

Here's what my code looks like. Has anyone else tried creating RadTreeView programmatically?

        protected override void CreateChildControls() 
        { 
            Controls.Clear(); 
 
            try 
            { 
                    if (!Page.IsPostBack) 
                    { 
                        m_Tree = new RadTreeView(); 
                        m_Tree.NodeExpand += new RadTreeViewEventHandler(m_Tree_NodeExpand); 
 
                        foreach (MyDataItem mdi in SomethingThatReturnsItems) 
                        { 
                                RadTreeNode node = CreateNode(mdi); 
 
                                if (node != null
                                    m_Tree.Nodes.Add(node); 
                        } 
 
                        Controls.Add(m_Tree); 
            } 
            catch (Exception ex) 
            { 
                Log.LogEvent("Error building tree.", ex); 
            } 
 
            base.CreateChildControls(); 
        } 
 
 
        void m_Tree_NodeExpand(object sender, RadTreeNodeEventArgs e) 
        { 
            foreach (MyDataItem mdi in SomethingThatReturnsChildItems) 
            { 
                RadTreeNode node = CreateNode(mdi); 
 
                if (node != null
                    e.Node.Nodes.Add(node); 
            } 
 
            e.Node.Expanded = true
        } 
 
        private RadTreeNode CreateNode(MyDataItem kf) 
        { 
            try 
            { 
                RadTreeNode node = new RadTreeNode(); 
                node.Text = kf.HomePage.CmsPage.Title; 
                node.Value = kf.ID.ToString(); 
                node.NavigateUrl = kf.HomePage.DefaultUrl; 
                node.ExpandedImageUrl = EXPANDED_FOLDER; 
                node.ImageUrl = CLOSED_FOLDER; 
 
                if (kf.HasChildren) 
                    node.ExpandMode = TreeNodeExpandMode.ServerSideCallBack; 
 
                return node; 
            } 
            catch (Exception ex) 
            { 
                Log.LogEvent("Error building tree node.", ex); 
                return null
            } 
        } 
 


2 Answers, 1 is accepted

Sort by
0
Vesko
Top achievements
Rank 2
answered on 05 Feb 2010, 03:23 PM
"When I migrated the code to the CompositeControl, I was no longer able to set the ExpandMode property at the TreeView level, only at the node level."

You cannot set the ExpandMode at the treeview level in any case. This is a property of the RadTreeNode class and should be set per node only.
0
Accepted
Jeff
Top achievements
Rank 1
answered on 11 Mar 2010, 09:24 PM
I got back to work on this issue and figured out the problem. Entirely my fault and related to CompositeControl implementation. It had nothing to do with Telerik.

I was only creating the TreeView control on the initial page load. When the NodeExpand event was posted to the server, the TreeView control wasn't there to service it.

Here's what the corrected code looks like:

        protected override void CreateChildControls() 
        { 
            Controls.Clear(); 
 
            try 
            { 
 
                    // The next three lines were moved out of the !IsPostBack block. Problem solved. 
                    m_Tree = new RadTreeView(); 
                    Controls.Add(m_Tree); 
                    m_Tree.NodeExpand += new RadTreeViewEventHandler(m_Tree_NodeExpand); 
 
                    if (!Page.IsPostBack) 
                    { 
                        foreach (KnowzyFile kf in KnowzyFile.GetKnowzyFileChildren(ParentFileID)) 
                        { 
                                RadTreeNode node = CreateNode(kf); 
 
                                if (node != null
                                    m_Tree.Nodes.Add(node); 
                            } 
                        } 
            } 
            catch (Exception ex) 
            { 
                Log.LogEvent("Error building tree.", ex); 
            } 
 
            base.CreateChildControls(); 
        } 
 
 

Tags
TreeView
Asked by
Jeff
Top achievements
Rank 1
Answers by
Vesko
Top achievements
Rank 2
Jeff
Top achievements
Rank 1
Share this question
or