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. Advertisements

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:
    648
    jongmin
    Jul 16, 2003
  2. NotYetaNurd
    Replies:
    1
    Views:
    609
    John Saunders
    Nov 7, 2003
  3. Celine
    Replies:
    3
    Views:
    19,403
    James Thomas
    Sep 3, 2004
  4. tanya foster
    Replies:
    3
    Views:
    4,026
    tanya foster
    May 18, 2006
  5. harryaya

    Session attributes lost after postback

    harryaya, Nov 9, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    1,838
    Alvin Bruney [MVP]
    Nov 9, 2006
  6. ton
    Replies:
    0
    Views:
    616
  7. JimLad
    Replies:
    0
    Views:
    708
    JimLad
    Jan 26, 2010
  8. Wen Ou

    controls in placeholder were lost after postback

    Wen Ou, Dec 1, 2004, in forum: ASP .Net Web Controls
    Replies:
    7
    Views:
    965
    Wen Ou
    Dec 4, 2004
Loading...