Home - Forums-.NET - FlyTreeView (ASP.NET) - How to Change Text of Node?

FlyTreeView (ASP.NET)

Technical support and KB related to the FlyTreeView control

This forum related to following products: FlyTreeView for ASP.NET

How to Change Text of Node?
Link Posted: 12-Sep-2008 10:23
Hi,

I have a tree that has 2 levels of nodes. They both use Content Templates on the server for then they are initially rendered.

The top level node displays amongst other things a count of it's child nodes.

The user, after expanding the parent node can end up adding a child node. On the server, I would like to have the top level node have it's text re-rendered, which would show the updated count.

I first started by trying to update the node.Text property, but found that this was an empty string. I even checked in the Page_PreRender method to make sure I was checking at the last possible place...I would think whatever was in the Content Template is used to set the Text property of the node, but I must be wrong on this...

I then tried updating the node.Attribute that I am using to store the count and then is expressed in the Content Template by doing  in the ContentTemplate. I then was hoping to find a method to force this particular node to be rerendered. I did not find an obvious way to do this though...

What is the best way to do what I am doing, short of rerendering the whole Tree and reexpanding the node that I was just looking at? That is what I am doing now and I'm looking for a better more efficient solution.

Thanks,
Rich
Link Posted: 14-Sep-2008 22:22
Rich,

FlyTreeNode has a ContentContainer control, that hosts server content of node.
You can use this property to get access to server side content of node.
Link Posted: 15-Sep-2008 13:41
Hi EvgenyT,

Thanks for the reply. I'm not having any success doing this.

Previously my node's content template looked something like this:


...  prices


I then changed it to

...  prices


I tried several things but my last resort was to use my tree's OnPreRender event to go and set the text on this Literal object by doing...


protected void myTree_PreRender(object sender, EventArgs e)
{

        
        foreach (FlyTreeNode node in myTree.Nodes)
        {
            //set price count label
            if (node.ContentContainer != null)
            {
                 Literal priceCountText = (Literal)node.ContentContainer.FindControl("ltPriceCount");
                 priceCountText.Text = node.Attributes["priceCount"];
            }

       }
}


The first time my tree renders, ContentContainer is NULL, so my code setting the text is never called. This is issue # 1 I have. When the tree shows initially, my price count is not shown...On subsequent renders of the tree, the ContentContainer now exists and my code to set the priceCount Literal is called, but again, the Text is never updated (issue #2).

What should I be doing instead? Be aware the way I am populating my tree is by doing:

myTree.Nodes.Add(productNode);

I never call DataBind() on my Tree.

My previous way of just outputting the count via  worked, but I was never able to update the text properly. I would revert to this, but I also had found that I could never change the text of the node once it was set (my initial question in this thread). I ended up repopulating the tree, which was far from ideal.

Your suggestion of using a server control makes senses, but does not work at all for me.

Thanks,
Rich
Link Posted: 15-Sep-2008 20:02
Rich,

FlyTreeView itself sets ContentContainer properties at PreRender stage.
So you need to handle PreRenderComplete instead.

Text property is ignored when ContentTemplate is used. So even if you have something in Text, it wont be visible.
Link Posted: 16-Sep-2008 07:04
Hi EvgenyT,

How do I handle the PreRenderComplete event? I do not see this exposed on the FlyTreeView. I only see PreRender.

Thanks,
Rich
Link Posted: 16-Sep-2008 07:14
This is page level event. Not event of FlyTreeView.
So just create a handler:
void  Page_PreRenderComplete(object sender, EventArge e)
{
..
}

Or override OnPreRenderComplete page method.
Link Posted: 16-Sep-2008 19:41
This worked for me. Thanks for the help.

Rich