Home - Forums-.NET - FlyTreeView (ASP.NET) - Templates Not Applied to Populate On Demand Nodes

FlyTreeView (ASP.NET)

Technical support and KB related to the FlyTreeView control

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

Templates Not Applied to Populate On Demand Nodes
Link Posted: 19-Oct-2006 22:39
FlyTreeView for ASP.NET 2.0 v4.1.1.42

This one has me completely stumped.

I am using templates to format my Nodes at one of three levels (Company, Site, Person). These templates contain one or more controls, such as labels, linkbuttons, images, with each Node being created programmatically and the templates setting the control properties using attribute values (such as ImageUrl='')

Originally I was populating the complete depth of the Tree on each search, so although 'PopulateOnDemand' was set to true, it didn't mean anything as all the Nodes already existed. Now I have been asked to reduce the load on the back end database and only return the minimum dataset possible (hence the need for true populate on demand) - and I control the original expanded level of the treeview based on the depth of the search, by setting ExpandedLevel to either 1, 2 or 3 when the top level Nodes (level 1, still only 1 root node at level 0) are populated.

What I find is that any Node which is populated on demand does not have its template applied the first time. The correct number of Nodes are shown in the correct positions and I can see that the attributes exist and the NodeTypeID is set correctly both server side (stepping through the code) and client side (capturing the selected event and returning one of the attributes and the NodeTypeID), but the Nodes are not being displayed using the templates. On a subsequent postback the Nodes are rendered correctly. It is only the templates that are not being applied - if I set the node.Text value, for example, programmatically this does get displayed OK.

Setting PostBackOnExpand=\"true\" half solves it, but the Nodes initially expand empty then a full postback fills in the missing info, which looks a bit clumsy and causes 2 lookups on the database for each node, which kind of defeats the object.

Any help would be much appreciated.
Chris.
Link Posted: 20-Oct-2006 02:43
Chris,
Actually server-side templates do not work with on demand nodes population.
There are several issues that cannot be solved. Like saving and restoring state for nested controls loaded on demand. It means that every node is a server-side control with nested child controls. But ASP.NET controls may have many different client-side dependencies when being rendered to client-side - like registering client handlers, css rules and so on. FlyTreeView cannot handle all of this, because it means that FlyTreeView should be an ASP.NET host and implement parts of ASP.NET to save and rerender . That is why it cannot be solved today.

For you problem. Typically the ASP.NET built-in caching framework may help in many cases. For instance, you may cache required data into Page.Cache and use it instead of calling database every time.
Link Posted: 20-Oct-2006 03:00
Thanks for the info Evgeny. I'm actually glad it wasn't just me being stupid! If it's a limitation then it's a limitation. I either work with it or around it.

One of the main reasons I've used this control over any others is that your support is absolutely superb.

Thanks again.
(By the way, does any one else's Visual Studio 2005 crash when a FlyTreeView is selected in Design mode and you click the A>Z sort button on the Properties (F4) window??? Happens to me every time...)
Link Posted: 03-Nov-2006 00:45
I've just updated from v4.1.1.42 to v4.1.2.58 and note that it breaks my use of Server templates.

For me, server templates were the whole reason for using this Treeview, and populate on demand is highly desirable. With v4.1.1.42, I was able to use postbackonexpand to render the server templates correctly (albeit with 2 calls to the database as stated above).

In v4.1.2.58, both postbacks are still happening (populate on demand and expand) but the templates are not applied on the second postback. Your changes document refers to a fix for Server Templates, but in my instance it's a backwards step.

Anything I can do to get this working again other than rely on an superseded version?

Many thanks.
Link Posted: 03-Nov-2006 08:29
This sounds like a bug in v4.1.2.58. It definitely fixes older but. But it seems like it also introduces a new one.

We hope to get it solved during this weekend.
Link Posted: 05-Nov-2006 07:47
Please download the latest build that contains a fix for the issue.
Link Posted: 05-Nov-2006 23:17
Thanks for your efforts Evgeny - as fast as ever.

On first glance, this fixes the problem, but unfortunately it introduces 2 new ones, one minor but one very major.

The major issue is nodes becoming jumbled when populate on demand is used after a childnodes.clear() method has occured. My single Root node stays static and I clear and fill its childnodes every time a search is performed using FlyTreeView1.Nodes[0].ChildNodes.Clear();. The second time a search is performed (hence the first time any childnodes are cleared and then repopulated), all looks well until I expand one of the newly filled nodes (which invokes a populate on demand). This then jumbles up all the nodes in the TreeView (including the siblings of the expanded node).

I'm guessing this is a viewstate issue???

The minor issue is the 'Loading' text remaining after populateondemand in some instances. I can reproduce this at will, but have yet to find the exact circumstances that cause it. 4.1.1.42 did not produce this issue with the exact same codebehind.

Hard to tell if these 2 new issues were present in 4.1.2.58 because I couldn't tell which node was which.

Thanks again...
Link Posted: 06-Nov-2006 00:27
We were trying to implement different server template test cases using various combinations. The problem seems to be in the Clear() method that does not remove Control object of treenode from the container collection of its parent.

So we have a new testing build here, and here's a special download link for you:
http://download.9rays.net/treeview_asp.net_2/flytreeview_asp2_test.zip

We will able to publish it after some necessary steps, but please try it for your case first. So we can make sure it finally solves the issue.

Regarding 'Loading' text message. We've not succeeded to reproduce this problem here. Hope to get to it soon.


Also I can say some words regarding implementations of on demand population.
There two ways. It seems that you're using the PopulateNodes event handler:

protected void Page_Load(object sender, EventArgs e)
{
    flyTreeView.Nodes[0].ChildNodes.Clear();
    flyTreeView.Nodes[0].PopulateNodesOnDemand = true;
}
protected void flyTreeView_PopulateNodes(object sender, NineRays.WebControls.FlyTreeNodeEventArgs e)
{
    FlyTreeNode ftn = new FlyTreeNode(\"Text\", \"Value2\");
    ftn.NodeTypeID = \"interest\";
    e.Node.ChildNodes.Add(ftn);
}


But it your case should be better not to handle the PopulateNodes event, but NodeExpandedChanged event instead:

protected void flyTreeView_NodeExpandedChanged(object sender, NineRays.WebControls.FlyTreeNodePropertyChangedEventArgs e)
{
    if (e.Node.Expanded == true && e.Node == flyTreeView.Nodes[0])
    {
        e.Node.ChildNodes.Clear();
        FlyTreeNode ftn = new FlyTreeNode(\"Text\", \"Value1\");
        ftn.NodeTypeID = \"interest\";
        e.Node.ChildNodes.Add(ftn);
    }
}

Note: In both cases the PopulateNodesOnDemand is set to true, and the second case does not use Page_Load to clear its nodes.

The second implementation is more performance effective way for the case.
Link Posted: 06-Nov-2006 02:33
No improvement with this version I'm afraid.

You are right in that I am using the onpopulatenodes event. I've changed one of my TreeView instances to use your recommended approach to see what performance benefits I might gain over time (same jumbling of nodes occurs still of course).

Let me know if I can provide more information to help find the issue.

Thanks again.
Link Posted: 06-Nov-2006 02:47
Actually my last comment wasn't quite true. There is an improvement in the test version - the nodes are still corrupting but not as much as before.

For instance, with v4.1.2.91, the Root node itself was being corrupted, but in the latest version it is not ( I saw it once, but that might have been a cache problem?). The corruption does also seem to come and go, but it isn't predictable.

I am continuously performing a search, then expanding a node, performing a search, expanding the same node etc. The Clear() method is only called when the search button is pressed.

Every 3rd or 4th iteration things get unjumbled. In between, the nodes are swapped around (but not as badly as before).

Hope this helps.