Home - Forums-.NET - FlyTreeView (ASP.NET) - Exception From Node Drag n Drop Move

FlyTreeView (ASP.NET)

Technical support and KB related to the FlyTreeView control

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

Exception From Node Drag n Drop Move
Link Posted: 09-Nov-2006 22:29
Didn't notice this bug in v4.1.1.42 but it's definately in v4.1.3.175.

Dragging and dropping a node within my treeview occasionally (roughly 30% of the time, and every time thereafter) this exception.

Please advise.



[NullReferenceException: Cannot find node (n50f597ddb4aa4175a4bb60165926434e) in the treeview hierarchy that should handle client-side event: NodeSelected]
   NineRays.WebControls.FlyTreeView.ApplyStateLog(String stateLog) +773
   NineRays.WebControls.FlyTreeView.System.Web.UI.IPostBackDataHandler.LoadPostData(String postDataKey, NameValueCollection postCollection) +61
   System.Web.UI.Page.ProcessPostData(NameValueCollection postData, Boolean fBeforeLoad) +897
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2547
Link Posted: 09-Nov-2006 23:01
Let's take a simple case with drag-and-drop:

    DragDropName=\"name\" DragDropAcceptNames=\"name\">
    
        
            
            
            
            
            
        
    



Does this code raise the error?
What browser? And what treeview settings do you have?

Ideally please provide a small sample code that raises exception.

Thank you in advance.
Link Posted: 06-Feb-2007 01:26
Hi !
I have exactly the same ASP.Net \"yellow page\".
Seems to be a \"random bug\" (once every 10-15 moves or something like that, varying, unpredictable). I don't manage to reproduce the case at will to identify the problem. i lacked time, delivered yesterday
I didn't overload any javascript in my page, it's purely native/yours.
Someone suggested me a cache problem  ???

Also : why is the nodemoved method executed twice ? The \"if node isnothing\" test isn't enough to exit sub on second occurence. The parentnodelevel sometimes is set to \"0\", and not nothing, and may interfer with real D&D at these levels (code executed as wished but twice => errors).

I guess my customer won't appreciate it but i have no idea where my error is  !!!
thanks

my nodemoved code :

        If IsNothing(e.Node.Parent) Then
            Exit Sub
        ElseIf e.Node.Parent.Level = 0 Then
            'le deuxieme passage dans la fonction provoque des erreurs dans ce cas !!!!
      'occurs sometimes even if the 1 level was not concerned with the move
            Exit Sub
        End If

        Dim ls_from_id As String = e.PreviousParent.Value.ToString
        Dim ls_to_id As String = e.Node.Parent.Value
        Dim ls_moved_id As String = e.Node.Value

  '*********************
  'database access here
  '*********************

        'rafraichissement de l'origine
        Dim items As NineRays.WebControls.FlyTreeNodeCollection = Me.TreeView1.Nodes(0).ChildNodes.FindByValue(ls_from_id, True)
        If items.Count > 0 Then
            Me.TreeView1.SelectedNode = items(0)
            Me.TreeView1.SelectedNode.ChildNodes.Clear()
            AddNodes(Me.TreeView1.SelectedNode.ChildNodes, Me.TreeView1.SelectedNode.Path)
'tried to solve the problem with this :
            If Me.TreeView1.SelectedNode.ChildNodes.Count > 0 Then
                Me.TreeView1.SelectedNode.ExpandLevel = 1
                Me.TreeView1.SelectedNode.Expanded = True
            Else
                Me.TreeView1.SelectedNode.ExpandLevel = 0
                Me.TreeView1.SelectedNode.Expanded = False
            End If
        End If

'i had to refresh destination node childnodes, as drop on a not expanded node doesn't fully populate it. Maybe origin refresh is useless but i did it for my enquiery

        'rafraichissement de la destination
        items = Me.TreeView1.Nodes(0).ChildNodes.FindByValue(ls_to_id, True)
        If items.Count > 0 Then
            Me.TreeView1.SelectedNode = items(0)
            Me.TreeView1.SelectedNode.ChildNodes.Clear()
            AddNodes(Me.TreeView1.SelectedNode.ChildNodes, Me.TreeView1.SelectedNode.Path)
            If Me.TreeView1.SelectedNode.ChildNodes.Count > 0 Then
                Me.TreeView1.SelectedNode.ExpandLevel = 1
                Me.TreeView1.SelectedNode.Expanded = True
                Dim items_repl As NineRays.WebControls.FlyTreeNodeCollection
                items_repl = Me.TreeView1.Nodes.FindByValue(ls_moved_id, True)
                If items_repl.Count > 0 Then
                    Me.TreeView1.SelectedNode = items_repl(0)
                End If
            Else
                Me.TreeView1.SelectedNode.ExpandLevel = 0
                Me.TreeView1.SelectedNode.Expanded = False
            End If
        End If

  'a sub call of my own, to forget nothing:
        refresh_details(Me.TreeView1.SelectedNode.Value, Me.TreeView1.SelectedNode.NodeTypeID)
Link Posted: 06-Feb-2007 04:13
Sorry !!!

the error is not on node selected but node expanded !!!

but the reason is expected to be the same, the node is not found to handle the client script
Link Posted: 06-Feb-2007 09:33
I have an idea.

Actually you should change treeview layout within the NodeMoved handler.

Instead of this, you should record changes somewhere and apply them in PageLoad or later.


The reason of the error can be that you're changing treeview layout during Node event stage (e.g. remove some nodes from it) and treeview framework cannot apply further changes for removed nodes.

Also, I took my previous example:
    DragDropName=\"name\" DragDropAcceptNames=\"name\" PostBackOnDropAccept=\"true\" OnNodeMoved=\"ftvMenu_NodeMoved\" >
    
        
            
            
            
            
            
        
    


Added the OnNodeMoved handler and PostBackOnDropAccept handler to make treeview postback immediately after each D&D. I have my blank ftvMenu_NodeMoved called only once for each page load.


Could please create a simple page using my code and make it raising errors? Probably you'll need to add something specific to this code.
Link Posted: 13-Feb-2007 06:04
Evgeny, I didn't reply to this thread earlier because I didn't have time to keep creating examples, and I've now moved to another project.

However, your latest version (v4.1.4.156) seems to have improved things. Looks like:

- 08.02.07         FlyTreeNode.Remove() and FlyTreeNodeCollection.Clear() method didn't always correctly cleared ContentContainer control used with server-side templates. Fixed.

might have been the culprit!
Regards
Link Posted: 14-Feb-2007 23:09
Update.

The issue (still) occurs when a treenode is dropped onto another node which is not yet expanded - (PopulateNodesOnDemand = true).

I use server templates, so I have to postback when a node is dragged or the templates are not applied. This postback fully rebuilds the tree. The error does not occur when dragging to an already expanded node, only to a non-expanded node. It makes no difference if the target node already contains child nodes or not.
Link Posted: 15-Feb-2007 00:31
This postback fully rebuilds the tree.

This can be a reason.

Do you rebuild the treeview in node-level event handler like NodeMoved?

The FlyTreeView fires node-level events one by one (like NodeMoved, NodeExpanded, etc.) during the LoadPostData stage. If you rebuild FlyTreeView at this stage then your FlyTreeView instance will not be able to find nodes for subsequent node events. And this it fires exception you get.

You should probably make any changes to FlyTreeView in a Page_Load or later to avoid the problem.
Link Posted: 15-Feb-2007 03:01
Yes, I was rebuilding the tree at the nodemoved event. I've moved this to Page_Load which seems to have fixed the issue.

Out of interest, I've done this by setting a Session variable flag in the node moved event which I check for at Page_Load. If the flag is set, it means the node moved event has fired and the tree should be rebuilt (clearing the flag afterwards of course). Is there a better way to do this? - I don't like using Session variables in this fashion.

Thanks again Evgeny.
Link Posted: 15-Feb-2007 03:32
Yes, using Session in this case is a bad practice.

There's a more simple way.

just add a new variable to your page code like this way:

private bool rebuildRequiredFlag = false;
private void MyNodeMovedHandler(...) {
    rebuildRequiredFlag = true;
}

protected void  Page_Load(...) {
   if (rebuildRequiredFlag)
   {
        // rebuild here
   }
}