Custom TreeNode typing lost after postback

Discussion in 'ASP .Net Web Controls' started by John Bankhead, Oct 30, 2006.

  1. [.NET 2.0]
    I have inherited from TreeNode to create my own FaultTreeNode, which
    contains three additional properties and some modifications to RenderPreText
    and RenderPostText. I have no problem adding instances of FaultTreeNode to a
    standard TreeView. Rendering of the nodes occurs as expected. I can step
    thru the code and see that the nodes are of type FaultTreeNode.

    The problem occurs during the postback. The treeview is recreated by the
    system, but the treenodes are no longer of type FaultTreeNode, but just
    TreeNode. Nor am I able to cast them to FaultTreeNodes. [Unable to cast
    object of type 'System.Web.UI.WebControls.TreeNode' to type
    'Volvo.VITNA.VolvoLink.Insight.FaultTreeNode'] As a result, I am no longer
    able to access the information stored in those additional properties.

    Below is a simplified representation of my code. is there something wrong
    with the approach?

    protected void Page_Load(object sender, EventArgs e)
    {
    if (!Page.IsPostBack)
    {
    FaultTreeNode _root = new FaultTreeNode("Fault Code Filter", -1,
    "");
    _root.FilterType = NodeType.NONE;
    _root.ChildNodes.Add(AddChildNodes());
    treeCtrl.Nodes.Add(_root);
    }
    ListCheckedNodes(tree.Nodes);
    }

    void ListCheckedNodes(TreeNodeCollection nodes)
    {
    int count = nodes.Count;
    for (int i = 0; i < count; i++)
    {
    try
    {
    FaultTreeNode ftn = (FaultTreeNode)(nodes);
    if (ftn.FilterType == NodeType.NONE)
    ListCheckedNodes(nodes.ChildNodes);
    {
    if (ftn.Checked) submitted.Items.Add(ftn.Text);
    }
    }
    catch (Exception ex)
    {
    string x = ex.Message;
    x = x;
    }
    }
    }
    --
    John Bankhead
     
    John Bankhead, Oct 30, 2006
    #1
    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. Steve C. Orr, MCSD

    Re: lost all of data after postback....

    Steve C. Orr, MCSD, Jul 15, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    552
    jongmin
    Jul 16, 2003
  2. tanya foster
    Replies:
    3
    Views:
    3,785
    tanya foster
    May 18, 2006
  3. ton
    Replies:
    0
    Views:
    522
  4. JimLad
    Replies:
    0
    Views:
    523
    JimLad
    Jan 26, 2010
  5. Phil H

    TreeNode objects inaccesible during postback

    Phil H, Oct 10, 2006, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    367
    Phil H
    Oct 10, 2006
Loading...

Share This Page