Home - Forums-.NET - FlyTreeView (ASP.NET) - JS Error on Creating Tree Programmatically

FlyTreeView (ASP.NET)

Technical support and KB related to the FlyTreeView control

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

JS Error on Creating Tree Programmatically
Link Posted: 08-Jan-2008 18:54
Hi. Currently I'm evaluating the FlyTreeView for ASP.NET 2.0.

I add the tree programmatically in Page.Load like following:

protected void Page_Load(object sender, EventArgs e)
    {
    FlyTreeView tree = new FlyTreeView();
    //tree.ID = "mytree";

    for (int i = 0; i < 10; i++)
    {
        FlyTreeNode node = new FlyTreeNode();
      node.Text = "node" + i.ToString();
      tree.Nodes.Add(node);
    }

    this.Controls.Add(tree);
    }


When I run, VS pop-up an error message saying "Microsoft JScript runtime error: Object required", then a line of javascript is highlighted. The highlighted line is "if(!_1.firstChild)", where the "_1" is null (pls see file attached). The same error pop-up regardless of whether I assign the ID for tree or not.

What I do just is just a simple page load. I found same posts from the forum that implement the similar code, but I get this error. I'm using IE7. Any clue? TIA
waifoong
Link Posted: 08-Jan-2008 19:17
The reason is in the line:
this.Controls.Add(tree);

This adds treeview after closing tag , and causes error when treeview runtime cannot find client-side element of treeview.

What you need is to create a placeholder, or use Page.Form control to append child control to.
Like this:
this.Form.Controls.Add(tree);

Should work without errors.
Link Posted: 08-Jan-2008 19:23
I have tried here Using VS 2005 and firefox 2.0. It worked perfectly and I haven't got any error.
Try creating a new project and then try may be you have added something that creates problem.
Link Posted: 08-Jan-2008 22:20
Hi. Tq for you both quick reply. Your code works fine.

In fact, that is my testing on creating tree programmatically. Due to some customization requirements, we are developing some custom controls for our needs, and tree is one of our controls. We created a class and inherit directly from NineRays.WebControls.FlyTreeView. Then we programmatically add our tree control (inherit from NineRays.WebControls.FlyTreeView) into the panel of a form.

The moment the form is being loaded, there is a javascript error(see attachment). before that we inherited directly from FlyTreeView version 1.1(forgot the namespace), it works fine, but the Js error pop-up once we upgraded to version 2.

I try to see whether your reply above applied to this case, but seem that they are different scenarios. Do you have any idea why is that so.

TIA
waifoong
Link Posted: 08-Jan-2008 22:40
Again, the error may arrive because client-side treeview script cannot find its element.
How do you create and add treeview (your inherited class)?

I've just created a class that inherits FlyTreeView. And everything seems to go ok in case of programmatic creating.

Could you please post here your treeview implementation code, so we can get the same error here (and debug it)?
Link Posted: 09-Jan-2008 17:04
Even though the javascript error pop-up, but the assigned nodes are rendered correctly on the page, just that there is no response or css applied if we try to click the +/- to expand/collapse or mouse over the node text.

Sorry that i unable to send you the sample as it is too much work to make a simplified version. Will try again to solve the issue.

Thank you for your replies.

waifoong
Link Posted: 09-Jan-2008 22:12
[quote="waifoong"]Even though the javascript error pop-up, but the assigned nodes are rendered correctly on the page, just that there is no response or css applied if we try to click the +/- to expand/collapse or mouse over the node text.

Yes, same for CSS and javascript - both seems to have problems with treeview. Looks like something prevents.

[quote="waifoong"]
Sorry that i unable to send you the sample as it is too much work to make a simplified version. Will try again to solve the issue.

Anyway, if you have any thoughts of what is the reason (99% - regarding your control hierarchy/execution lifecycle) - please let me know - so we can try to emulate and debug it locally.

Thanks.