Home - Forums-.NET - FlyTreeView (ASP.NET) - nodes not shown properly after code-behind add

FlyTreeView (ASP.NET)

Technical support and KB related to the FlyTreeView control

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

nodes not shown properly after code-behind add
Link Posted: 18-Dec-2007 21:26
William,

I cannot image any reason to assign FlyTreeView instance to a static variable.

FlyTreeView in as control, it operates in a context of ASP.NET request. Once it finished, the instance is destroyed.
And again recreated when postback/callback/etc. comes to the page with FlyTreeView.

This is ASP.NET page/control execution lifecycle.
Link Posted: 19-Dec-2007 04:24
[quote="hellowahab"]Why you want flyTreeView be a static variable. Simply you have to pass the reference of the control you have got on your page. The thread or function simply have access to that contol or surely populate it. Or if you are having your function on the same page all you need is, to access the control directly.

Simply pass the reference of control. Not a temporary variable


            public class ThreadProc : ITask
            {

private FlyTreeView FlyTreeView1 = null;

                public ThreadProc(ref FlyTreeView FlyTreeView11)
                {
                    FlyTreeView1 = FlyTreeView11;
                }
                ...
            }


simply pass the control on your page, and code should be like that


           public class ThreadProc : ITask
            {

                //---------------private FlyTreeView FlyTreeView1 = null;

                public ThreadProc(ref FlyTreeView FlyTreeView11)
                {
                    FlyTreeView1 = FlyTreeView11;
                }

private void DoSomeTask()
{
ThreadProc(FlyTreeView1);   //FlyTreeView1 being you control on web page
}


            }


I get a compiler error if FlyTreeView is not static.

The exact error message is:

C:\Documents and Settings\William Johnston\My Documents\Visual Studio 2005\WebSites\DavidClientAjax\App_Code\InstructionProc.cs(142,68): error CS0038: Cannot access a nonstatic member of outer type 'DavidClient.InstructionProc' via nested type 'DavidClient.InstructionProc.ThreadProc'

Using a local copy of FlyTreeView for ThreadProc compiles correctly.

I also set ViewState to be static since I cannot pass a Property by reference.

Thanks,
William Johnston
Link Posted: 19-Dec-2007 04:29
[quote="EvgenyT"]William,

I cannot image any reason to assign FlyTreeView instance to a static variable.

FlyTreeView in as control, it operates in a context of ASP.NET request. Once it finished, the instance is destroyed.
And again recreated when postback/callback/etc. comes to the page with FlyTreeView.

This is ASP.NET page/control execution lifecycle.


I get a compiler error if not using a local copy or a static FlyTreeView variable.

The exact error message is:

C:\Documents and Settings\William Johnston\My Documents\Visual Studio 2005\WebSites\DavidClientAjax\App_Code\InstructionProc.cs(142,68): error CS0038: Cannot access a nonstatic member of outer type 'DavidClient.InstructionProc' via nested type 'DavidClient.InstructionProc.ThreadProc'

Do you know which FlyTreeView variable to debug to view the addition of nodes?  

Thanks,
William Johnston
Link Posted: 19-Dec-2007 04:41
William,

You should not ever use static variables in ASP.NET.
It is not guaranteed by ASP.NET server that postback request will come to same process, or ASP.NET process would not be recycled and launched again (and loose all static data).

ViewState object is completely handled by ASP.NET engine, you shouldn't have any static variable holding viewstate.
It is saved and loaded entirely by ASP.NET engine.

I believe you should read more about ASP.NET page execution lifecycle and about ASP.NET state management.
Link Posted: 19-Dec-2007 04:46
[quote="williamj"]
Do you know which FlyTreeView variable to debug to view the addition of nodes?  

You need to get FlyTreeView instance which you want to add nodes to.

It is in your page, in a composite control (as part of it) or anywhere else in ASP.NET control hierarchy.
Link Posted: 19-Dec-2007 05:47
[quote="EvgenyT"][quote="williamj"]
Do you know which FlyTreeView variable to debug to view the addition of nodes?  

You need to get FlyTreeView instance which you want to add nodes to.

It is in your page, in a composite control (as part of it) or anywhere else in ASP.NET control hierarchy.


To be more specific, do you know the exact debug variable in FlyTreeView object in order to debug the addition of nodes?  I could not find the correct variable.

Thanks,
William Johnston
Link Posted: 19-Dec-2007 05:49
What do you mean?

You need to check what you have in yourFlyTreeViewInstance.Nodes property.
Link Posted: 19-Dec-2007 23:12
If you are still getting error post you project ( after extracting/removing confidential information). So I can debug it and let you know where you are mistaken. Only post the project with the relevant info remove the access to the database by using any table or dataset which is dynamically populated and act as a data source so the project can run as expected. I will debug it and upload it.
Link Posted: 27-Dec-2007 09:18
Here is a sample app which populates nodes.

I am having problems with IE 7 and could not run the app on my side.

If you could wait a few days, I will provide another project.

Regards,
William Johnston
Link Posted: 27-Dec-2007 09:19
[quote="hellowahab"]If you are still getting error post you project ( after extracting/removing confidential information). So I can debug it and let you know where you are mistaken. Only post the project with the relevant info remove the access to the database by using any table or dataset which is dynamically populated and act as a data source so the project can run as expected. I will debug it and upload it.


I have uploaded project files.

Thanks,
William Johnston