Home - Forums-.NET - FlyTreeView (ASP.NET) - Problems with Viewstate on large amounts of data?

FlyTreeView (ASP.NET)

Technical support and KB related to the FlyTreeView control

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

Problems with Viewstate on large amounts of data?
Link Posted: 30-Nov-2006 02:31
Hi,

I have a strange effect when i have more FlyTreeViews on one aspx.
I'm displaying filesystem security information on my page.
So I need one TreeView for displaying my Filesystem structure (and this can be huge structures)
I'm using the same strategy for reading folders/subfolders like in the online demo.
If the user selects one directory he can view the security settings of it.
The security information is displayed by 2 additional treeviews.
So far so good.

The problem is, that after the data binding of the 2 \"permission trees\" the first one (directory tree) is not able to populate nodes anymore.
Every expanding results in:
Error: 'firstChild' is null or not an object

When I use FlyContextMenu I also get the error message that the control cannot be found on right-click (also after data binding on the permission trees)

First I thougt that it has to do with the FlyContextMenu and i kicked them all out.
But this was not the problem.
My second thought was that there could be a problem with the ViewState.
So I tried to put the 2 \"permission\" trees in a seperate aspx and only kept the large directory tree in the original one.
And ... voila, it works!
So i guess it could be a problem with saving/reading ViewState (just an assumption)

So, does anybody have an idea how to keep my 3 trees on one page?
Would be great, because the version with the \"extra\" aspx page is not very user friendly.

Thanx a lot
Link Posted: 30-Nov-2006 05:55
I forgot to say that this error occurs after every postback.

Here the implementation in the code-behind file:

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not Page.IsPostBack Then
            If Not Session(\"BrowseFolderPermissions\") Is Nothing Then
                labShare.Text = Session(\"BrowseFolderPermissions\").ToString()
                ResolveFirstLevel(labShare.Text)
            End If
        End If
    End Sub


    Private Sub ResolveFirstLevel(ByVal sharePath As String)

        Dim rootNode As New FlyTreeNode(HttpUtility.HtmlEncode(sharePath.ToUpper), sharePath.ToUpper)
        rootNode.NodeTypeID = \"Root\"
        rootNode.CanBeSelected = False
        rootNode.PopulateNodesOnDemand = True

        treeDirectories.Nodes.Clear()
        treeDirectories.Nodes.Add(rootNode)
        AddSubFolders(rootNode, sharePath)

    End Sub

    Private Sub AddSubFolders(ByRef fathernode As FlyTreeNode, ByVal fatherpath As String)

        Dim dirs() As String

        dirs = Directory.GetDirectories(fatherpath)

        Dim objDir As DirectoryInfo
        Dim newNode As FlyTreeNode

        For Each dir As String In dirs
            objDir = New DirectoryInfo(dir)

            newNode = New FlyTreeNode(HttpUtility.HtmlEncode(objDir.Name), objDir.FullName)
            newNode.NodeTypeID = \"Dir\"

            Dim splitted() As String = objDir.FullName.Split(\"\\\")
            fathernode.ChildNodes.Add(newNode)
            newNode.PopulateNodesOnDemand = splitted.GetLength(0)  0

        Next

    End Sub

    Protected Sub treeDirectories_PopulateNodes(ByVal sender As Object, ByVal e As NineRays.WebControls.FlyTreeNodeEventArgs)

        AddSubFolders(e.Node, e.Node.Value)

    End Sub

Link Posted: 30-Nov-2006 07:31
I've tried to reproduce the error:
The ASPX code with 3 treeviews and one context menu for all of them:

    Height=\"200px\" ContextMenuID=\"contextMenu\">

    Height=\"200px\" ContextMenuID=\"contextMenu\">

    Height=\"200px\" ContextMenuID=\"contextMenu\">


    
        
        
    


And the same code-behind as yours, but with some modifications (just to make it work):
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not Page.IsPostBack Then
            'If Not Session(\"BrowseFolderPermissions\") Is Nothing Then
            '                labShare.Text = Session(\"BrowseFolderPermissions\").ToString()
            ResolveFirstLevel(treeDirectories, \"c:\\program files\")
            ResolveFirstLevel(treeDirectories1, \"c:\\program files\")
            ResolveFirstLevel(treeDirectories2, \"c:\\program files\")
            'End If
        End If
    End Sub


    Private Sub ResolveFirstLevel(ByVal treeview As FlyTreeView, ByVal sharePath As String)

        Dim rootNode As New FlyTreeNode(HttpUtility.HtmlEncode(sharePath.ToUpper), sharePath.ToUpper)
        rootNode.NodeTypeID = \"Root\"
        rootNode.CanBeSelected = False
        rootNode.PopulateNodesOnDemand = True

        treeview.Nodes.Clear()
        treeview.Nodes.Add(rootNode)
        AddSubFolders(rootNode, sharePath)

    End Sub

    Private Sub AddSubFolders(ByRef fathernode As FlyTreeNode, ByVal fatherpath As String)

        Dim dirs() As String

        dirs = Directory.GetDirectories(fatherpath)

        Dim objDir As DirectoryInfo
        Dim newNode As FlyTreeNode

        For Each dir As String In dirs
            objDir = New DirectoryInfo(dir)


            newNode = New FlyTreeNode(HttpUtility.HtmlEncode(objDir.Name), objDir.FullName)
            newNode.NodeTypeID = \"Dir\"

            Dim splitted() As String = objDir.FullName.Split(\"\\\")
            fathernode.ChildNodes.Add(newNode)
            newNode.PopulateNodesOnDemand = splitted.GetLength(0)  0

        Next

    End Sub

    Protected Sub treeDirectories_PopulateNodes(ByVal sender As Object, ByVal e As NineRays.WebControls.FlyTreeNodeEventArgs)

        AddSubFolders(e.Node, e.Node.Value)

    End Sub


And it works ok. Postback also succeeds. No errors.

Could you please change something within the code to reproduce the error, so we can test it here and finally find the problem?
Link Posted: 01-Dec-2006 04:46
Hi Evgeny,

I think I found the problem.

I tried the same trees you posted and again the same code here on my machine.
And I had always the same error.
I was really going mad here ... I just couldn't find the error.

Then I thought, maybe there's a problem with my IE version.
I'm running IE 6.0.2900.2180.xpsp2 ... on my machine.
The whole company uses this browser at the moment ))

And now I tried the whole thing with Mozilla Firefox -> and the problem doesn't exist anymore *lol*
The irony of the story: I'm working in a team called \"CoreTeam for Windows Related Systems\" and we are also responsible for the software on our clients )))
I'll try now with IE7. I think it will also work fine.
Maybe I have a good reason now to plead for an IE7 rollout on our clients (just about 30.000 machines) ... hehe... great! ))

Nevertheless, thank you for your time and your support

*greetz*
Andreas
Link Posted: 01-Dec-2006 05:39
It's me again ...

It certainly also works fine with IE7.
And it also brings much more rendering performance on the client.

Thanks again
Link Posted: 01-Dec-2006 06:46
Do you have some tips how to make it run with IE6?

Web browsers are a very sensitive topic.
And IE7 was recently released. So i can't imagine that we are officially allowed to use it in the next months.

Maybe we can configure the IE6 to make it work.
But I don't have any idea which settings I should use.
I already set the security settings to \"Low\" and allowed all ActiveX things because of the ASP.NET AJAX things.

Is there something else I can try?

regards
Andreas
Link Posted: 01-Dec-2006 07:45
Andreas,

Did you test exactly the same code that I'd posted here?

Actually I tested my sample with both IE6 and FF browsers.
Everything goes ok. Version 6.0.2900.2180.xpsp_sp2_gdr.050301-1519, using default settings.

Do you have any antivirus software that may block some javascript? If yes please try to disable it temporary.

Also please try to open the same page using another computer at your network with IE6.

There may be another source of the problem. I'm using Program Files folder for my sample. My one differs from yours. May be there's a special character in your program files folder or it has more subfolders. So could you please test the page with a simpler case. For example, create  a temporary folder with several subfolders.

Thank you for cooperation.

P.S. Yes, IE7 is a major step for Microsoft in performance and reliability. But anyway we need to support older browsers also.
Link Posted: 01-Dec-2006 09:30
Hi,

I took the same code, yes.
I didn't only scan \"program files\" but also some other testfolders where I've chosen very short and simple names such as \"Folder1\", \"Folder2_3\".
Strange characters cannot be the problem, even on our storage, because we don't allow any strange characters on the first 3 levels.
I'm only browsing till the first 3. On the third level I set \"PopulateNodesOnDemand\" to 'false' by default.
And before the postback every directory can be properly displayed.

I also turned off the \"Trend Micro Office Scan\"

I further tried on some different computers, even on the webserver itself.
I tried in debug mode via the local webserver of Visual Studio.
Also deployed on a webserver.
Always the same error on IE6.

I debugged the whole thing as good as possible.
The event \"OnPopulateNodes\" only fires before the first postback.
After I do a postback ... and I'm trying to populate nodes again, I still receive the java script error: firstChild is null or not an object.

I'm not a specialist, but it seems to me that the content of the tree (which is stored in the Viewstate) is not coming back from the Viewstate properly.
I'm also \"losing\" the context menus after postback. When I rightclick the tree ->
\"cannot find context menu id: blabla...\"
But everything after the first postback.

These errors only occur on the tree where I do \"live browsing\" ... reading data from the filesystem when nodes are populated.

My other treeviews have a dataset bound.
So the data is evaluated first, and then the complete dataset is bound to the tree. This works without problems. I can postback as much as I want to.

I sent an email to some of my colleagues. There are some guys who are very familiar with OS, software and especially our client environments and security settings.
Maybe they can also help in this topic.

It must be unbelievable for you ... but I can only tell you the fact that it's not working.

I just see that you released a new Build today.
Mine is from the 28th (Tuesday)
But I don't think you considered my problem yet ... especially when you cannot reproduce it ;-)
But I'll also try with the new build.

Maybe I can organise that we can do some remote assistance next week.
Or I fix it on the weekend ... if I have enough motivation.

greetz
Link Posted: 01-Dec-2006 10:49
Try the following link:
http://www.9rays.net/asp.net_2/treeview/TestCase.aspx

Do you experience errors when testing the page?
Link Posted: 01-Dec-2006 11:44
damn ... it works
maybe i have sth. in my masterpage that produces a conflict.
in my content page i had exactly the same code you posted.
a content placeholder and just the few lines for the tree.
my colleague embedded some javascript in the masterpage (for navigation etc.)
i'll try to throw that out .... and let you know the results.
thanks