Home - Forums-.NET - FlyTreeView (ASP.NET) - The tree is very slow when using PopulateOnDemand

FlyTreeView (ASP.NET)

Technical support and KB related to the FlyTreeView control

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

The tree is very slow when using PopulateOnDemand
Link Posted: 12-Feb-2008 01:44
Hi

I use PopulateOnDemand because of large content.
Everything has worked fine during development, but now I have started to put in real data and the tree doesn’t cope with the amount of data.

The tree structure is about 15 levels deep. It works perfect when you expand the first 10 levels since there is only a small amount of sub nodes for each node you expand.
Each node on the 10:th level contains about 300 sub nodes and the first time that amount of data is loaded in the tree it works perfect, only a very small delay, just as you expect since there is a fare amount of HTML for the browser to load.
But after that it seems like the browsers memory for the tree is full. It takes about 2 min for the tree to expand a node that only contains a very small amount of data.

If you reload the page it works perfect until you expand a node that contains a large amount of data.

Is there a way to disable the tree to store which nodes that has been expanded? I.e. that every time you expand a node the content will be populated, regardless if the node has been expanded before?  

I have tested the application on both IE 6 and Firefox 2.0 with the same result.
Link Posted: 12-Feb-2008 03:39
There's a possible improvement in such cases. Basically you can "reset" collapsed nodes every postback.
To do this you need to clear ChildNodes collections of collapsed nodes and set the their PopulateOnDemand to true.
This way you can save some memory.
Link Posted: 12-Feb-2008 04:47
-Great!

Can you give me an example of the code?
Link Posted: 12-Feb-2008 05:47
Like this

protected void Page_Load(object sender, EventArgs e)
{
    // clear collapsed child nodes every postback
    if (IsPostBack && !IsCallback)
    {
        FlyTreeNodeCollection collapsedNodes =
            FlyTreeView1.FindAll(delegate(FlyTreeNode node)
            {
                return
                    node.Expanded == false &&
                    node.PopulateNodesOnDemand == false;
            });
        foreach (FlyTreeNode node in collapsedNodes)
        {
            // clear child nodes
            node.ChildNodes.Clear();
            // and make them populate on demand again
            node.PopulateNodesOnDemand = true;
        }
    }
}
Link Posted: 12-Feb-2008 21:59
That did not help.
Is there a way to collapse all other open nodes and clear there ChildNodes collections when you click on a new node?
I.e. the only expanded branch is the one you have just clicked.

If you could provide any sample code, that would be great.
Link Posted: 13-Feb-2008 01:11
My code was server side, if you mean client-side, then you can try to handle the collapse node event and remove child nodes from it. I'm not sure that browser will free resources in this case, but we can try.

I'll post here the client-side code if you're interested.
Link Posted: 13-Feb-2008 21:40
That would be great! Thanks
Link Posted: 14-Feb-2008 01:13
OK. Try this snippet:





Do not forget to set treeview's OnNodeEventJavascript to flyTreeView_nodeEvent .