Home - Forums-.NET - FlyTreeView (ASP.NET) - Problem when using the tree view on an ajax loaded page

FlyTreeView (ASP.NET)

Technical support and KB related to the FlyTreeView control

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

Problem when using the tree view on an ajax loaded page
Link Posted: 11-Mar-2008 00:50
Hi,

I'm currently having an issue using javascript on the tree view when the tree view is on a page that is retrieved using ajax.
see http://www.dynamicdrive.com/dynamicindex8/dhtmlwindow/

My initial problem was that CFlyTreeView could be found. I found a solution to this, but now in the following javascript
var treeview = CFlyTreeView.getInstanceById(treeviewID);
treeview is always null.

When the page is not retrieved using ajax, but just navigated to all works perfectly.

Thanks,
Stefan
Link Posted: 11-Mar-2008 01:00
Stefan,

What is treeviewID? Is it client ID?
Add
document.getElementById(treeviewID) - is it null?
Link Posted: 11-Mar-2008 13:45
treeViewID is fine, it's the ClientID of the treeView. It does not return null when doing getElementById.
I encountered a similiar problem before when I was trying to access CFlyTreeView.getInstanceById before the initialized event had been received. So from this I am thinking that some startup script needs to be performed before you can access the treeview instance. However, as the entire page is retrieved by ajax and displayed using the mechanism in the modal window library, none of the startup scripts seem to get run. Could this be causing the problem? If so is there a way I can call the initialisation methods manaully?

Stefan
Link Posted: 12-Mar-2008 04:51
Stefan,
You should consider using the  FlyTreeView.OnInitializedJavascript  handler to do your stuff, since this is the event which guarantees the treeview is initialized.

If used within AJAX updatepanel, it is fired every time treeview is refreshed.
Link Posted: 12-Mar-2008 21:41
Hi,

The page isn't on an AJAX update Panel, it is retrieved in a way that mimics a modal window.

As a result though the FlyTreeView.OnInitializedJavascript is never fired. I presume because none of the startup scripts are run that are on this page. I have however worked around this by after the page is retrieved I can run my own javascript if i desire. However I don't know how to initialize the treeview.

Stefan
Link Posted: 12-Mar-2008 21:44
Stefan,

Can you create me a test page/small web app with FlyTreeView in "modal window"?
So I can help you to find the way to initialize treeview in this case.

P.S. You can simply attach ZIP file to your post.
Link Posted: 17-Mar-2008 02:52
Hi,

Here's a simple sample of the problem I am having.
Basically the default page has a button which launches the modalish ajax page. You can see in the javascript I try and get the instance of the tree view but the element is defined but not the tree view instance. I have tried numerous different ways, but have had no success.

You can also navigate directly to the modal.aspx page to see that the same javascript works.

Thanks,
Stefan
Link Posted: 18-Mar-2008 04:33
Stefan,

Great, I've managed to make it working with FlyTreeView.

First, you need to fix the Default.aspx.cs file at Page_Load method:
- remove the
//Page.ClientScript.RegisterClientScriptResource(typeof(NineRays.WebControls.FlyTreeView), "_70");

- add the following line (this will force ASP.NET to emit few init scripts) - normally not required, when any control on the page calls this method:
Page.GetPostBackEventReference(this);


Also, download the latest version of FlyTreeView:
http://www.9rays.net/download.aspx?productFamily=TreeView_ASP.NET_2
It contains the FlyTreeView.ForceAjaxRenderer property that you need to set to true.
We've introduced this setting for cases like yours - when it is not possible for treeview to determine that it is rendered in an AJAX context.

Also, at AjaxLoad function, comment out the lines:
//    var treeview = CFlyTreeView.getInstanceById('FlyTreeView1');
//    alert("The instance of FlyTreeView1 is " + treeview);

CFlyTreeView is not available at this stage, instead, Initialize function is automatically called by treeview.