This is a migrated thread and some comments may be shown as answers.

Delete radtreenode index out of range

6 Answers 95 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Gabriele
Top achievements
Rank 1
Gabriele asked on 08 May 2012, 10:46 AM
Hi all,

 I have a radtreeview with radtreeviewcontextmenu.
 When I right-click on node and select "delete" from contextmenu  I got the following error message :

"Microsoft JScript  run-time error: Sys.WebForms.PageRequestManagerServerErrorException: Index out of range...."

aspx:
<telerik:RadAjaxLoadingPanel ID="ralp" runat="server" />
<telerik:RadAjaxPanel ID="rap" runat="server" LoadingPanelID="ralp">
<telerik:RadTreeView  ID="elenco" runat="server" Width="100%" Height="300px" CheckBoxes="True" 
TriStateCheckBoxes="true" 
CheckChildNodes="true"  
EnableViewState="false" 
AllowNodeEditing="false"
OnClientContextMenuItemClicking="onClientContextMenuItemClicking"
OnClientContextMenuShowing="onClientContextMenuShowing" 
OnNodeEdit="elenco_NodeEdit" 
EnableDragAndDrop="True" 
OnClientNodeDropping="onNodeDropping" 
OnClientNodeDragging="onNodeDragging" 
MultipleSelect="true" 
EnableDragAndDropBetweenNodes="true" PersistLoadOnDemandNodes="False">         
<DataBindings><telerik:RadTreeNodeBinding Expanded="True"/></DataBindings>
</telerik:RadTreeView>
</telerik:RadAjaxPanel>

My client side function to manage context menu click :

function onClientContextMenuItemClicking(sender, args) {

        var menuItem = args.get_menuItem();
        var treeNode = args.get_node();
        var treeView = $find("<%= elenco.ClientID %>");
        var node = treeView.findNodeByText(args.get_node().get_text());
       // menuItem.get_menu().hide();

 switch (menuItem.get_value()) {

case "elimina":
                var result = confirm("Si vuole cancellare la cartella: " + treeNode.get_text());
                eventArgs.set_cancel(!result);
                var allNodes = treeView.get_allNodes();
                if (allNodes.length < 1) { alert("La struttura รจ vuota!"); return false; }
                var selectedNode = treeView.get_selectedNode();
                if (!selectedNode) { alert("Selezionare prima un elemento"); return false; }
                if (allNodes.length == 1) {
                if (!confirm("Si vuole davvero eliminare l'ultimo elemento presente?"))
                return false;                }
                var selectedNode = treeView.get_selectedNode();
                //alert(selectedNode.get_text());
                treeView.trackChanges();
                var parent = selectedNode.get_parent();
                //alert(parent.get_text());
                parent.get_nodes().remove(selectedNode);
                treeView.commitChanges();
                return false;
                break;     }    }

What's wrong ?
I've tried to remove all drag'n'drop client side events (OnClientNodeDropping,OnClientNodeDragging) but same result
Diasbled ViewState , nothing to do..

Might you help me please ?
Thank you

Gabriele








6 Answers, 1 is accepted

Sort by
0
Plamen
Telerik team
answered on 11 May 2012, 08:25 AM
Hi Gabriele,

 
I have inspected the code that you posted but could not reproduce the error locally. I am attaching my test sample web page that worked properly at my side so please review it and if you still observe the issue please let me know what else should be added in order to reproduce it locally.  

Hope this will help.

Regards,
Plamen Zdravkov
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Gabriele
Top achievements
Rank 1
answered on 11 May 2012, 04:04 PM
Thanks so much Plamen Zdravkov,

I forgot some code behind.. sorry
I've discovered what causes the error .
In code behind I use the ContextMenuItemClick server side event to intercept the client operations 
My aim is to store the tree structure into db after every single crud client side operation
Here we go

Protected Sub elenco_ContextMenuItemClick(ByVal sender As Object, ByVal e As Telerik.Web.UI.RadTreeViewContextMenuEventArgs) Handles elenco.ContextMenuItemClick

       Try
            For Each operation As ClientOperation(Of RadTreeNode) In elenco.ClientChanges
                Dim node As RadTreeNode = operation.Item
                Select Case operation.Type
                    Case ClientOperationType.Insert
                      'new
                        Call salva_struttura(node.Text, e.Node.Value.Substring(1, e.Node.Value.Length - 1), "new")
                        Exit Select
                        Case ClientOperationType.Remove
                            'delete
                            Call salva_struttura(node.Text, e.Node.Value.Substring(1, e.Node.Value.Length - 1), "del")
                            Exit Select
                    Case ClientOperationType.Update
                        Dim update As UpdateClientOperation(Of RadTreeNode) = DirectCast(operation, UpdateClientOperation(Of RadTreeNode))
                        'edit
                        Exit Select
                End Select
            Next
        Catch ex As Exception
            Throw (ex)
        End Try
       
    End Sub

salva_struttura is a routine to store the tree structure in my postgresql db. It works correctly.
Furthermore if you comment or cancel all the code inside the above routine the error persists..!!
Try with just...

Protected Sub elenco_ContextMenuItemClick(ByVal sender As Object, ByVal e As Telerik.Web.UI.RadTreeViewContextMenuEventArgs) Handles elenco.ContextMenuItemClick 
End Sub

...and you should still get the index error !

It's very odd, isn't it ?
thanks

Gabriele
0
Plamen
Telerik team
answered on 16 May 2012, 03:59 PM
Hello Gabriele,

 
I have tested again but could not observe the unusual behavior again. Here is a video of my test. Please review it and let me know what else should be added to my code in order to observe it. 

Would you please specify if it can be reproduced in our on-line demo as well?

All the best,
Plamen Zdravkov
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Gabriele
Top achievements
Rank 1
answered on 17 May 2012, 03:32 PM
Hi Plamen , 

You're very very kind!
I'll try to clean up my solution and rebuild it from scratch.

Just one more little help..
Two quick questions :

1.Is it correct my approach ? 
CRUD operations  just client side and then, after each one,  server side db storage ?
Is there in your web forum an exhaustive working example according to my method ?

2.Each one of the following client side activity
NODE INSERT : tree.get_nodes().add(node);
NODE DELETE: node.get_parent().get_nodes().remove(node);
NODE UPDATE: node.startEdit();
get intercepted through the server side event ContextMenuItemClick and 
 by routine "For Each operation As ClientOperation(Of RadTreeNode) In elenco.ClientChanges..." ? 
I mean, that happens automatically after every nodeclick ?? Even the update one ?

I hope I explained myself properly
Thanks again

Gabriele
0
Plamen
Telerik team
answered on 22 May 2012, 03:54 PM
Hi Gabriele,

 
1.If you are trying to trigger from the client side some CRUD events you can use an Ajax Request to trigger the server actions.

2.Unfortunately it is not very clear what exactly are you trying to achieve and why do you handle the client events after the server one. Would you please explain the reason for implementing it this way?

All the best,
Plamen Zdravkov
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Gabriele
Top achievements
Rank 1
answered on 24 May 2012, 12:58 PM
Hi Plamen ,  

as I wrote before I 'm tryin' to implement the following solution :

- Client operator will operate on radtreeview just by client side 
- Operations allowed are: insert node, edit node, delete node (CRUD)
- All above operations are selectable from a radtreeviewcontextmenu
- I would like to manage every CRUD activity on client side through javascript functions
- javascript  functions for insert,edit and delete are already up and perfectly working (except the index problem with node deletion..)
- After every crud operation I want to store in my postgresql db the treeview structure obviously server side
- As you suggest me now I'm tryin' to get every single operation on client side through the server side event ContextMenuItemClick 
-  Inside the above event I'm tryin' to intercept every CRUD activity with the following routine :

  For Each operation As ClientOperation(Of RadTreeNode) In elenco.ClientChanges
                Dim node As RadTreeNode = operation.Item
                Select Case operation.Type
                    Case ClientOperationType.Insert
    Case ClientOperationType.Remove
                    Case ClientOperationType.Update
                End Select 
Next

INSERT : I can intercept the insert operation and get the newnode stored in my db
DELETE: I have index out of range problem on remove node
UPDATE: I can't get on server side the javascript  "node.startEdit();"

At last I guess I'll leave this "client side to serve side method" doing everyting  on server side..

English is not my language so I hope I have expressed myself clearly and correctly this time
Thanks again Plamen Zdravkov for your help and attention. 
You can consider this thread closed, Bye !!
Gabriele

Tags
TreeView
Asked by
Gabriele
Top achievements
Rank 1
Answers by
Plamen
Telerik team
Gabriele
Top achievements
Rank 1
Share this question
or