Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > Customizing a TreeNode's viewstate

Reply
Thread Tools

Customizing a TreeNode's viewstate

 
 
Keith Patrick
Guest
Posts: n/a
 
      01-03-2006
I 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?


 
Reply With Quote
 
 
 
 
Keith Patrick
Guest
Posts: n/a
 
      01-03-2006
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!


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problems with ViewState: "function 'ViewState.get_Item' evaluated and returned null" Steph ASP .Net 2 05-11-2011 02:35 PM
Errors: Failed to load viewstate. & Validation of viewstate MAC failed. sck10 ASP .Net 6 09-01-2006 05:59 PM
Loading usercontrols, viewstate problem, slighly different from all others "viewstate uc problems" please help... ujjc001 ASP .Net 0 07-27-2005 01:52 PM
Viewstate errors... how do I get viewstate working? mark ASP .Net Building Controls 0 02-20-2004 02:17 PM
Corrupted ViewState (Yes, another issue concerning viewstate) Ben Rush ASP .Net 2 12-05-2003 04:17 PM



Advertisments