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

Index was out of range. Must be non-negative and less than the size of the collection.

3 Answers 511 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Kevin
Top achievements
Rank 1
Kevin asked on 14 May 2009, 05:58 PM
I am using the following client-side code to delete a node from a tree:
        function tvNavigation_ClientNodeDropping(sender, args) { 
            var elem = args.get_htmlElement(); 
            if(elem==null || elem.id != "TrashCan") { 
                args.set_cancel(true); 
                return
            } 
             
            var tree = $find('<%= tvNavigation.ClientID %>'); 
            tree.trackChanges(); 
            try { 
                var sourceNode = args.get_sourceNode(); 
                var parent = sourceNode.get_parent(); 
                parent.get_nodes().remove(sourceNode); 
            } 
            catch(ex) { console.log(ex); } 
            tree.commitChanges(); 
        } 

It successfully delete the node client-side but throws this exception in the console:

[Exception... "'Sys.WebForms.PageRequestManagerServerErrorException: Sys.WebForms.PageRequestManagerServerErrorException: Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index' when calling method: [nsIDOMEventListener::handleEvent]" nsresult: "0x8057001c (NS_ERROR_XPC_JS_THREW_JS_OBJECT)" location: "JS frame :: chrome://firebug/content/spy.js :: onHTTPSpyReadyStateChange :: line 497" data: no]

Also, the node does not get deleted server-side.  Running the project in debug mode, I never see where or how the exception get raised.  Is there any solution to this problem?

* I am using Q1 2009 SP1 controls



3 Answers, 1 is accepted

Sort by
0
Simon
Telerik team
answered on 15 May 2009, 02:17 PM
Hi Kevin,

Have you handled the server-side NodeDrop event? Do you have AJAX on the page (UpdatePanel/RadAjaxPanel/RadAjaxManager), which updates the TreeView after the drag-and-drop operation completes at the client?

All the best,
Simon
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Kevin
Top achievements
Rank 1
answered on 15 May 2009, 04:33 PM
Yes, the treeview is using RadAjaxManager.  The NodeDrop event is being handled server-side.  I just can't figure out why Visual Studio doesn't halt execution as soon as it hits the exception when I'm in debug mode.  I will re-visit the logic in my NodeDrop event handler to see if that is the real issue.
0
Simon
Telerik team
answered on 16 May 2009, 09:18 AM
Hello Kevin,

In this case, it is most likely that there is a server-side exception with the error message, which is displayed by the PageRequestManager.

You could set a breakpoint the server-side NodeDrop handler and debug to find out where is thrown the exception.

Greetings,
Simon
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
TreeView
Asked by
Kevin
Top achievements
Rank 1
Answers by
Simon
Telerik team
Kevin
Top achievements
Rank 1
Share this question
or