Home - Forums-.NET - FlyTreeView (ASP.NET) - TreeView added Server Side to a Custom Control

FlyTreeView (ASP.NET)

Technical support and KB related to the FlyTreeView control

This forum related to following products: FlyTreeView for ASP.NET

TreeView added Server Side to a Custom Control
Link Posted: 30-Oct-2006 16:35
I am trying to build a tree in a control that is then added to the page via the code behind.  The problem I am having is that the tree doesn't render correctly.  In this scenario, the tree renders as just a textual list.  There is no functionality, styles, images, etc.  Will the tree work this way?  Will the tree work as a control added to another control that is then added to the web page via the code behind?  (Like the tree added to a custom webpart that is built dynamically on the server side).

If so what do I need to do?  I found a few posts talking about the aspnet_client/ninerays files and then modifying the FlyTreeView.ClientRuntimePath.  However, I don't have the ninerays directory under my aspnet_client virtual on my development workstation.  Nor is this directory on my server.  As a result, I am not sure what to do from here

Thanks,

Jamey
Link Posted: 31-Oct-2006 06:38
aspnet_client/ninerays and FlyTreeView.ClientRuntimePath refer to FlyTreeView for ASP.NET 1.1.

The FlyTreeView for ASP.NET 2.0 runtime files are embedded into the control assembly resources. So it does not require special folder for it.

Will the tree work as a control added to another control that is then added to the web page via the code behind?



Yes. It will. Here's tested code that works. It implements composite control and loads it into the page using two ways.

App_Code/CustomControlWithFlyTreeView.cs:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using NineRays.WebControls;

namespace MyControls
{
    public class CustomControlWithFlyTreeView : Control, INamingContainer

    {
        protected override void CreateChildControls()
        {
            Controls.Clear();
            base.CreateChildControls();
            FlyTreeView ftv = new FlyTreeView();
            ftv.ImageSet = FlyTreeViewImageSet.WinXP;
            ftv.PostBackOnSelect = true;

            ftv.SelectedStyle.BackColor = System.Drawing.Color.Red;
            ftv.HoverStyle.BackColor = System.Drawing.Color.Blue;

            ftv.Nodes.Add(new FlyTreeNode(\"Node\"));
            ftv.Nodes.Add(new FlyTreeNode(\"Node\"));
            ftv.Nodes[0].ChildNodes.Add(new FlyTreeNode(\"Node\"));


            Controls.Add(ftv);
            Controls.Add(new TextBox());

        }
    }
}
Link Posted: 31-Oct-2006 06:39
And CustomControlTest.aspx: [code] protected override void OnInit(EventArgs e) { base.OnInit(e); // Here is the proper place // containerPanel.Controls.Add(new MyControls.CustomControlWithFlyTreeView()); } protected void Page_Load(object sender, EventArgs e) { // but this also works containerPanel.Controls.Add(new MyControls.CustomControlWithFlyTreeView()); } Untitled Page
Inline declaration:
Creating on demand:
[/code]
Link Posted: 31-Oct-2006 16:00
Thank you.  As you know, the above code does work.  I have something in my control that is interfering with your tree and I am tracking that down.  

With the above code, I am having an issue with enabling it to do populate on demand.  I am simply trying to add your populate example (the flyTreeView_PopulateNodes using eh FileSystemNodes) to the example above without any luck.  I keep getting an error similar to what I would get if View State were not enabled.  However, view state is enabled.  Is it possible to perform the load on demand using the above code scenario?

Thanks!
Link Posted: 01-Nov-2006 00:34
Here's the changed code for populating nodes on demand.

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using NineRays.WebControls;

namespace MyControls
{
    public class CustomControlWithFlyTreeView : Control, INamingContainer

    {
        protected override void CreateChildControls()
        {
            Controls.Clear();
            base.CreateChildControls();
            FlyTreeView ftv = new FlyTreeView();
            ftv.ImageSet = FlyTreeViewImageSet.WinXP;
//            ftv.PostBackOnSelect = true;

            ftv.SelectedStyle.BackColor = System.Drawing.Color.Red;
            ftv.HoverStyle.BackColor = System.Drawing.Color.Blue;

            ftv.Nodes.Add(new FlyTreeNode(\"Node\"));
            ftv.Nodes.Add(new FlyTreeNode(\"Node\"));
            ftv.Nodes[0].ChildNodes.Add(new FlyTreeNode(\"Node\"));
            ftv.Nodes[1].PopulateNodesOnDemand = true;

            ftv.PopulateNodes += new FlyTreeNodeEventHandler(ftv_PopulateNodes);


            Controls.Add(ftv);
            Controls.Add(new TextBox());

        }

        void ftv_PopulateNodes(object sender, FlyTreeNodeEventArgs e)
        {
            e.Node.ChildNodes.Add(new FlyTreeNode(\"Populated Node\"));
            e.Node.ChildNodes.Add(new FlyTreeNode(\"Populated Node 2\"));
            e.Node.ChildNodes[0].PopulateNodesOnDemand = true;
        }
    }
}


What way do use to add the treeview into page controls hierarchy? Page_load, some event handler? It seems that the treeview misses LoadPostData stage. Or may be does not implement INamingContainer (like in my sample).