Customizing a TreeNode's viewstate

Discussion in 'ASP .Net Web Controls' started by Keith Patrick, Jan 3, 2006.

  1. 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?
     
    Keith Patrick, Jan 3, 2006
    #1
    1. Advertising

  2. 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, Jan 3, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Aditi Deo via .NET 247
    Replies:
    0
    Views:
    382
    Aditi Deo via .NET 247
    Jun 5, 2004
  2. naijacoder naijacoder
    Replies:
    1
    Views:
    685
    naijacoder naijacoder
    Sep 15, 2004
  3. naija naija
    Replies:
    0
    Views:
    510
    naija naija
    Sep 28, 2004
  4. tanya foster
    Replies:
    3
    Views:
    3,791
    tanya foster
    May 18, 2006
  5. Replies:
    0
    Views:
    168
Loading...

Share This Page