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

4 posts, 0 answers
  1. Kevin
    Kevin avatar
    16 posts
    Member since:
    Mar 2009

    Posted 14 May 2009 Link to this post

    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



  2. Simon
    Admin
    Simon avatar
    2281 posts

    Posted 15 May 2009 Link to this post

    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.
  3. Kevin
    Kevin avatar
    16 posts
    Member since:
    Mar 2009

    Posted 15 May 2009 Link to this post

    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.
  4. Simon
    Admin
    Simon avatar
    2281 posts

    Posted 16 May 2009 Link to this post

    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.
Back to Top