For Programmers: Free Programming Magazines  


Home > Archive > ASP .NET Webcontrols > October 2006 > Custom TreeNode typing lost after postback









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Custom TreeNode typing lost after postback
John Bankhead

2006-10-30, 7:34 pm

[.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[i]);
if (ftn.FilterType == NodeType.NONE)
ListCheckedNodes(nodes[i].ChildNodes);
{
if (ftn.Checked) submitted.Items.Add(ftn.Text);
}
}
catch (Exception ex)
{
string x = ex.Message;
x = x;
}
}
}
--
John Bankhead
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2009 codecomments.com