|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Customizing a TreeNode's viewstateI have a custom subclass of TreeNode that has to store it's own additional
viewstate to itself. However, the problem I run into is that even though the owning TreeView is itself a subclass that overrides CreateNode(), then calling TreeNode.LoadViewState(object), all ChildNodes are restored as TreeNode rather than DerivedTreeNode, so when they themselves have their viewstates restored, they are receiving modified viewstates (and basically, my viewstate is new Object[] { base.SaveViewState(), <newViewStateInfo> }) not that haven't had the 2nd element stripped out and thus results in an InvalidCastException as TreeNode.LoadViewState assumes the vs is of a different type. My question is: how can I override TreeNode.LoadViewState such that I can restore the child node hierarchy with the instances being of the correct subclass of TreeNode that knows how to handle the modified viewstate? Found the problem after using Lutz Roeder's .Net Reflector to look at
TreeNode and TreeNodeCollection. Basically, TreeNodeCollection is the problem, as it implements IStateManager, too. The problem was that my subclassed TreeNode wasn't passing the Owner (TreeView) ctor parameter to the base class, and TreeNodeCollection only calls CreateNode() (instead of new TreeNode()) if the owner is not null. I have a separate Owner property, so I wasn't noticing that a protected Owner property was null. Score 1 for having access to a decompiler! Keith Patrick wrote:
> Found the problem after using Lutz Roeder's .Net Reflector to look at Hi Keith,> TreeNode and TreeNodeCollection. Basically, TreeNodeCollection is the > problem, as it implements IStateManager, too. The problem was that my > subclassed TreeNode wasn't passing the Owner (TreeView) ctor parameter to > the base class, and TreeNodeCollection only calls CreateNode() (instead of > new TreeNode()) if the owner is not null. I have a separate Owner property, > so I wasn't noticing that a protected Owner property was null. Score 1 for > having access to a decompiler! I am having the same problem. Would you mind posting your custom TreeNode class and the changes you made that makes the whole thing work? Thanks a lot!
Any hints on how to do frames in ASP.Net 2.0?
Remove Dynamic User Controls from a collection Custom Treenodes in Treeview link on an entire row in a datagrid Would like to get two items from a dropdownlist DropDownList VS TextBox Gridview - Accessing a field value in current row controlToValidate property of compareValidator combo box customs TreeView |
|||||||||||||||||||||||