views:

414

answers:

3

I have a ASP.NET treeview populated with custom treenodes (ExtensionRangeTreeNode subclassed from TreeNode). On postback the treeview is populated with TreeNodes, not my custom treenode class.

What's up with this?

Thanks, BP

A: 

Without looking at your particular code, I can only assume that you custom TreeNode is not using ViewState. This would explain why it is not getting populated on postback.

ichiban
I thought of that. However, attempting to reload viewstate on postback yields this error:"Failed to load viewstate. The control tree into which viewstate is being loaded must match the control tree that was used to save viewstate during the previous request."BP
theBruce
A: 

DoesExtensionRangeTreeNode fully handle saving itself to the viewstate fully? If so, can you cast the returned nodes to that type?

Jared
+1  A: 

Hello,

This forum entry may answer the question :

Basically, it is said a custom treeview control has to be used. CreateNode function must be overriden to instanciate the right TreeNode type. Here, it would be ExtensionRangeTreeNode instead of "CustomTreeNode".

public class CustomTreeView : TreeView
{
    protected override TreeNode CreateNode()
    {
        return new CustomTreeNode(this, false);
    }
}

Of course, you will have to add the ExtensionRangeTreeNode(Treeview treeview, bool isRoot) constructor signature to your current ExtensionRangeTreeNode implementation.

controlbreak