Home - Forums-.NET - FlyTreeView (ASP.NET) - Create Tree and Context Menu from code-behind

FlyTreeView (ASP.NET)

Technical support and KB related to the FlyTreeView control

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

Create Tree and Context Menu from code-behind
Link Posted: 28-Jan-2008 04:28
For my current project i need tree view control to visualize hierarchy.
I try to use flyTreeView, but have some problems

when i try to create simple page i got javascript error 'null' is not null or object

Reproduce (Visual Studio 2005)

1. Create Web Application

protected FlyTreeView flytreeview;

protected override void CreateChildControls()
{
   flytreeview = new FlyTreeView();
   flytreeview.Nodes.Add("node1");
   .....
   Controls.Add(flytreeview);
}

Ctrl-F5

2. Are any examples how to create ContextMenu from code behind ?

if i create it in CreateChildControls
            contextMenu = new FlyContextMenu();
            contextMenu.ID = "contextMenu1";
            contextMenu.Items.Add(new FlyMenuItem("Move Up", "up"));
            contextMenu.Items.Add(new FlyMenuItem("Move Down", "Down"));
            contextMenu.Items.Add(new FlyMenuItem("Edit"));
            contextMenu.Items.Add(new FlyMenuItem("Delete"));
            this.Controls.Add(contextMenu);
            flytreeview.ContextMenuID = contextMenu.ClientID;
            this.Controls.Add(flytreeview);


when i try to show context menu with right click, i always get message that CFLyContextMenu with '.... here id ...' can not be found.

Thank you
Link Posted: 28-Jan-2008 04:38
The reason is that
this.Controls.Add(contextMenu);

adds the control after closing tag.

Use a placeholder for the controls (flytreeview and context menu), or use
this.Form.Controls.Add(contextMenu);

to add the controls before the closing  tag.
Link Posted: 28-Jan-2008 05:51
Thank you
This work in plain asp.net web application

I need to to this in WebPart in MOSS 2007,

Tree (expanding/сollapse) working right.

But when i try to access menu, i always get can't find CFlyContextMenu with id: ......

I think somehing wrongwith Id, but i can't find where to look for correct Id for context menu in html source code.
Link Posted: 28-Jan-2008 05:53
Oh, sorry I missed the issue.

You need to set
flytreeview.ContextMenuID = contextMenu.ID;
instead of ClientID