I found the problem with PopulateOnDemand with my treview class derived from System.Web.UI TreeView.
I made my
public class ParishTV : System.Web.UI.WebControls.TreeView
and also my TreeNode
public class ParishTVNode : TreeNode
{
public DateTime LastLoaded;
public ParishTVNode():base()
{
}
public ParishTVNode(string text, string value, string ImageURL, string navigateURL, string target): base(text, value, ImageURL, navigateURL, target)
{
LastLoaded = DateTime.Now;
}
public ParishTVNode(string s)
: base(s)
{
LastLoaded = DateTime.Now;
}
}
I assemble em in standalone dll and include in my project.
Also I downloaded adapters in source codes from http://www.asp.net/CSSAdapters/
added there adapter for ParishTV.
I registered
<%@ Register TagPrefix="Pari" Namespace="ParishNS" Assembly="ParishTV" %>
and create tree
I fill tree within OnInit eventhandler from DB.
Ah, also I made record for attaching adapter to my tree class:
<adapter controlType="System.Web.UI.WebControls.TreeView" adapterType="CSSFriendly.TreeViewAdapter" />
<adapter controlType="ParishNS.ParishTV" adapterType="CSSFriendly.ParishTVAdapter" />
Well, everything works fine When I do Not use populate on demand.
First problem occurs when I realised that OnInit in faired each time I click on node and tree is rebuild from scratch. okey, I removed OnInit and populate Tree with some nodes from aspx file useing
<Nodes>
<Pari:ParishTVNode Text="Inventory1" Value="1" Expanded ="false" SelectAction="Expand" PopulateOnDemand="true" />
<Pari:ParishTVNode Text="Inventory2" Value="2" Expanded ="false" SelectAction="Expand" PopulateOnDemand="true" />
<Pari:ParishTVNode Text="Inventory3" Value="3" Expanded ="false" SelectAction="Expand" PopulateOnDemand="true" />
</Nodes>
When OnPopulate occurs I create MY ParishTVNode:
TreeNode child = null;
switch (e.Node.Value)
{
case "1":
child = new ParishTVNode("Classical");
e.Node.ChildNodes.Add(child);
child = new ParishTVNode("Rock");
e.Node.ChildNodes.Add(child);
…
It works! but only once. when one node is populated it is ok, but then depending not on what node is populated somehow are created nodes with Correct text and correct values, but Not of My parishTVNode type but of Base TreeNode class ^^.
All new nodes from second OnPopulate firing are TreeNodes but not ParishTVNodes.
I create ParisTVNodes, and at the end of OnPopulate eventhandler they are ParishTVNodes, but when Adapter is trying to render em, first nodes are ParishTVNodes and these bad nodes are TreeNodes.
Help, please.
You need to override the CreateNode method. On postback, the TreeView has to reconstruct the tree from the viewstate. This method allows treeview extenders to use their own TreeNode types without experiencing the issue you’re dealing with.
Its pretty simple to do…