ExpandMode Property When Building Tree Programmatically

3 posts, 1 answers
  1. Jeff
    Jeff avatar
    51 posts
    Member since:
    Aug 2007

    Posted 02 Feb 2010 Link to this post

    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. Vesko
    Vesko avatar
    122 posts
    Member since:
    Mar 2009

    Posted 05 Feb 2010 Link to this post

    "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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Answer
    Jeff
    Jeff avatar
    51 posts
    Member since:
    Aug 2007

    Posted 11 Mar 2010 Link to this post

    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(); 
            } 
     
     

Back to Top