I have two radlistboxes on the page, where we could move items from one to the other. There's a Radcombobox which comes after this set of radlistboxes which goes for an autopostback.
Now, if I choose one item and move it to the other radlistbox and select an item from radcombobox which goes for a postback and save - it all works fine. But if I choose the option to add all items in a click and after the radcombobox postback, i get the following error.
[ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index]
System.Collections.ArrayList.get_Item(Int32 index) +10064164
System.Web.UI.StateManagedCollection.System.Collections.IList.get_Item(Int32 index) +17
Telerik.Web.UI.ControlItemCollection.get_Item(Int32 index) +22
Telerik.Web.UI.ClientStateLogPlayer`1.Remove(ControlItemCollection items, Int32 index) +58
Telerik.Web.UI.ClientStateLogPlayer`1.Play(ClientStateLogEntry entry) +453
Telerik.Web.UI.ClientStateLogPlayer`1.Play(IEnumerable`1 clientStateLogEntry) +165
Telerik.Web.UI.RadListBox.LoadClientState(RadListBoxClientState clientState) +66
Telerik.Web.UI.RadListBox.LoadPostData(String postDataKey, NameValueCollection postCollection) +230
System.Web.UI.Page.ProcessPostData(NameValueCollection postData, Boolean fBeforeLoad) +945
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2071
I cannot debug as well, as it doesnt hit any breakpoints. Fails before that.
I get the same error even if I choose all items in the left radlistbox one by one to the right radlistbox as well. Basically if the radlistbox is empty, and if the page goes for a postback, I get this error. If the page doesnt go for a postback - all good. So on postback, radlistbox is loosing its clientstate (dont know, am a newbie).
PS: Even after the postback, the state of the radlistboxes are maintained , ie. all items moved or unmoved remain the same.
<
td
>
<
telerik:RadListBox
ID
=
"lstAvailableItems"
ButtonSettings-Position
=
"Right"
EmptyMessage
=
"None"
AllowTransferOnDoubleClick
=
"true"
EnableDragAndDrop
=
"true"
PersistClientChanges
=
"true"
ViewStateMode
=
"Disabled"
Height
=
"100px"
AllowTransfer
=
"true"
TransferMode
=
"Move"
TransferToID
=
"lstSelectedItems"
SelectionMode
=
"Single"
Width
=
"200px"
runat
=
"server"
>
</
telerik:RadListBox
>
</
td
>
<
td
>
<
telerik:RadListBox
ID
=
"lstSelectedItems"
AllowTransferOnDoubleClick
=
"true"
EmptyMessage
=
"None"
PersistClientChanges
=
"true"
EnableDragAndDrop
=
"true"
Height
=
"100px"
Width
=
"200px"
SelectionMode
=
"Single"
ViewStateMode
=
"Disabled"
runat
=
"server"
>
</
telerik:RadListBox
>
</
td
>
29 Answers, 1 is accepted

I've made a sample page based on the mark-up you have provided trying to reproduce the issue, but to no avail.
Could you specify which version of the controls you are using?
Provide us with the servers-side code you are using and especially with the implementation of the "save" functionality that you perform upon post-back of the RadComboBox.
Probably you are trying to access items from the first listbox, which has already been transferred.
I'm sending the sample page I've tested with.
Regards,
Dimitar Terziev
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

I'm receiving a similar error when attempting to save changes. I have multiple RADListbox controls on one page inside of an HTML Table. Each table row contains a list box for Available Items and another on the right for the selected items. I only receive this error when I move all of the items from "Available" to the "Selected" - and there is already an empty "Available" list box control below the current row. If the row below it has items in the available list box control, it works just fine.
For example, I'm moving all items from list box #3 to list box #4, and list box #5 is already empty. After this update, I click save and get the error.
Row 1 - RADListBox 1 (Available) RADListBox 2 (Selected)
Row 2 - RADListBox 3 (Available) RADListBox 4 (Selected)
Row 3 - RADListBox 5 (Available) RADListBox 6 (Selected)
The controls are loaded programmatically in the page_init event. I have ensured that I have set the ID of each listbox control to make them unique. Although, I could not set the RadListBoxItem controls ID. It seems the form data is posted, but the list box cannot be found so it can be loaded during the event ProcessPostData(). I've verified the form fields exist in the postback using Fiddler.
Any help would be greatly appreciated.
Thanks,
Nathan
Please try setting the AutoPostBackOnTransfer property of the source RadListBox to true.
All the best,
Genady Sergeev
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

Hello,
This would require that we save the changes on every listbox change. Our UI builds up a number of "Shuttle Boxes" programmatically. We would prefer to not save the changes until the user has made all of their changes. Also peforming a postback would make it a bit slower (even though we have it wrapped in an Ajax update panel).
Do you have any other suggestions that may resolve this issue without setting it to postback on list item changes?
More Details:
I'm no longer recieving the error message, but still no list items in my List Box (rlbAvailable_124) on "Save_Click" event. This issue only occurs when the list box directly below it is empty (rlbAvailable_131). If I drag an item to (rlbAvailable_131) and save the changes, I can then go back to the page and drag an item from (rlbSelected_124) to (rblAvailable_124), click Save and it works. The problem also occurs if I drag an item from (rlbSelected_171) to (rlbAvailable_171) when the (rlbAvailable_124) is empty. Once I do this and click "Save", my Save_click event shows that (rlbAvailable_171) contains NO list items. Of course (rlbAvailable_124) is empty because it was originally empty. Could it be possible that the method that loads the Post Data is not recognizing the difference between these to "Available" list box controls and is unable to load the post data?
Example UI: Control on the left is a RadListBox for the "Available" Items, the control on the right is a RadListBox that contains the "Selected" items. There can actually be any number of rows and controls since they are added programmatically. The controls are loaded in Page_Init from a database source. I have grouped an "Available" RadListBox and "Selected" RadListBox together and call it a single Shuttle Box. In this case, I have a Shuttle Box on each row. The Shuttle Boxes are built up programmatically and loaded during Page_Init. There can be any number of rows, however, in this example I'm only using 3 rows.
------------------------------------------------------------------------------------------------------------------------
USER INTERFACE:
ROW 1:
ShuttleControl171_rlbAvailable_171 ShuttleControl171_rlbSelected_171
ROW 2:
ShuttleControl124_rlbAvailable_124 ShuttleControl124_rlbSelected_124
ROW 3:
ShuttleControl131_rlbAvailable_131 ShuttleControl131_rlbSelected_131
[SAVE] [CANCEL]
------------------------------------------------------------------------------------------------------------------------
PostBack Example:
Below is the process that occurs when a user clicks the "Save" button after making changes:
Page_Init
- Load RadListBox (list items added programmatically from a database source)
- After the controls have loaded, I have verified all list items are present (Original State).
Page_Load (Nothing)
Load View State (No ViewState for Rad Controls)
Load Post Data (Loads Post Data)
- This method should load the Post Data, but doesnt seem to be.
- This is also the location in which the error occurs (I'm no longer getting this error, but the previous error occured here)
- See Form Post Data example below (This method should be loading this form data)
btnSave_Click Event
- Each Control should have been updated with user changes and we can retrieve those values here
- My application is not saving correctly when the "Available" list box has no items because ProcessPostData failed to load it (ProcessPostData failing to load is just my theory)
Form Post Data Analysis:
The form post data seems to be fine. Below are the post data that was present during the "Save" button click event. The user moved one item from (rblSelected_124) list box to the (rlbAvailable_124) list box. The (rlbAvailable_131) list box directly below it was empty. When breaking on the Save click event, the (rlbAvailable_124) list box showed no list items present. It seems the items was not loaded as they should have been during ProcessPostData. However, if I break on the Page_init event before the Save click event is fired, I find that the original items gets loaded as original state (as it should). But when breaking on the Save click event, they are gone.
Form Post Data (Retrieved using Fiddler):
ctl00_ContentPlaceHolder1_tabWizard_pnlSettings_wzdSettings_ucUniqueCols_ShuttleControl124_rlbAvailable_124_ClientState
{"logEntries":[{"Type":1,"Index":"3","Data":{"value":"420","selected":false,"text":"n1"}}],"selectedIndices":[],"checkedIndices":[],"scrollPosition":0}
ctl00_ContentPlaceHolder1_tabWizard_pnlSettings_wzdSettings_ucUniqueCols_ShuttleControl124_rlbSelected_124_ClientState
{"logEntries":[{"Type":2,"Index":"3"}],"selectedIndices":[2],"checkedIndices":[],"scrollPosition":0}
ctl00_ContentPlaceHolder1_tabWizard_pnlSettings_wzdSettings_ucUniqueCols_ShuttleControl131_rlbAvailable_131_ClientState
{"logEntries":[],"selectedIndices":[],"checkedIndices":[],"scrollPosition":0}
ctl00_ContentPlaceHolder1_tabWizard_pnlSettings_wzdSettings_ucUniqueCols_ShuttleControl131_rlbSelected_131_ClientState
{"logEntries":[],"selectedIndices":[],"checkedIndices":[],"scrollPosition":0}
Thanks for you help!!
Nathan
The problem here is not a problem with RadListBox but with the AJAX. Whenever there is a button that triggers async postback that async postback should update the listboxes if transfer/reorder operations were done. I will try to explain why in the lines below:
When you transfer (reorder) items from the source listbox to the destination the changes are written to the client states of the both listboxes. This is done for the sake of playing the state on the server and correctly updating the view state of the both controls. What happens when you postback is precisely the same. Both listboxes play their client states and the changes in question take place. The source loses 3 items and 3 items are appended to the destination listbox. Then, both RadListBoxes clear their client states because they have already played the changes. Now, what happens when you don't update the listboxes is that they client state is not correctly cleaned. In fact it is not cleaned at all. However, the viewstate of the page is updated by RadAjaxPanel and the changes made to the listboxes are saved there. Then, on a subsequent postback both listboxes try to play the very same client state once again which leads to the error that you have faced. You can verify this behavior If you inspect the source/destination RadListBox ClientState using a tool like FireBug. Compare the situation when the listboxes are not updated by RadAjaxPanel and when they are updated.
In short, whenever changes are made to the client state of RadListBox the async postback should update the latter.
Kind regards,
Genady Sergeev
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

Even I am getting the similar error when I am doing a drag-drop from one listbox to another and clicked on submit button and a postback is happening.
How can we prevent this?
Regards,
kkr
As I've suggested to Nathan, please try setting the AutoPostBackOnTransfer property of the source RadListBox to true.
Kind regards,
Genady Sergeev
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

Unfortunatly this did not work for me. This actually caused the list box on the left to clear all list items other than the one I dragged over. It seems to have worked in all other cases such as dragging from the "Available" list boxes to the "Selected" list box, as well as the other way around when the list box below is not empty as described in the previous post. So when I drag from "Selected" back to "Available" and "Shuttle Box #3 (row 3)" has an empty "Available" list box, all other list items are cleared out. I think this occurs because it fails to load the Post Data (not view state) in this unique scenario.
I'm planning on putting together a code example to post. I hope to have this posted soon.
Thanks for all of your help!

I'm experiencing exactly the same problem with the RadListBox and setting the AutoPostBackOnTransfer property of the source ListBox control to true isn't an acceptable workaround for me because the reason I'm using Ajax is to prevent post backs. Could you please think of another solution? Thanks...
You can use the AutoPostBackOnTransfer with Ajax. Just place the RadListBox inside RadAjaxPanel or ajaxify it using RadAjaxManager. I will try to explain in the lines below why it is needed to use (ajax) postbacks instead of client-side transfer:
When you transfer (reorder) items from the source listbox to the destination the changes are written to the client states of the both listboxes. This is done for the sake of playing the state on the server and correctly updating the view state of the both controls. What happens when you postback is precisely the same. Both listboxes play their client states and the changes in question take place. The source loses 3 items and 3 items are appended to the destination listbox. Then, both RadListBoxes clear their client states because they have already played the changes. Now, what happens when you don't update the listboxes is that they client state is not correctly cleaned. In fact it is not cleaned at all. However, the viewstate of the page is updated by RadAjaxPanel and the changes made to the listboxes are saved there. Then, on a subsequent postback both listboxes try to play the very same client state once again which leads to the error that you have faced. You can verify this behavior If you inspect the source/destination RadListBox ClientState using a tool like FireBug. Compare the situation when the listboxes are not updated by RadAjaxPanel and when they are updated.
In short, whenever changes are made to the client state of RadListBox the async postback should update the latter.
Kind regards,
Genady Sergeev
the Telerik team
Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!


This post SAVED me. I was curious how you re-sorted the lists with partial postback.
Can you drop me a code snippet?
Thanks!

Hi Steve,
Here is what I've done:
1. I've put both the source and destination ListBox controls inside a Panel control:
<
asp:panel
id
=
"Panel"
runat
=
"server"
height
=
"100%"
width
=
"525px"
>
<
telerik:radlistbox
id
=
"ListBoxSource"
runat
=
"server"
allowtransfer
=
"true"
allowtransferondoubleclick
=
"true"
autopostbackontransfer
=
"true"
causesvalidation
=
"false"
height
=
"115px"
selectionmode
=
"Multiple"
skin
=
"Telerik"
transfermode
=
"Move"
transfertoid
=
"ListBoxDestination"
width
=
"275px"
>
</
telerik:radlistbox
>
<
telerik:radlistbox
id
=
"ListBoxDestination"
runat
=
"server"
allowtransferondoubleclick
=
"true"
causesvalidation
=
"false"
height
=
"115px"
selectionmode
=
"Multiple"
skin
=
"Telerik"
width
=
"245px"
>
</
telerik:radlistbox
>
</
asp:panel
>
2. I've put an AjaxManager to the top of the page to do the partial postback when items are transferred between the source and destination listboxes:
<
telerik:radajaxmanager
id
=
"AjaxManagerMain"
runat
=
"server"
>
<
ajaxsettings
>
<
telerik:ajaxsetting
ajaxcontrolid
=
"ListBoxSource"
>
<
updatedcontrols
>
<
telerik:ajaxupdatedcontrol
controlid
=
"Panel"
loadingpanelid
=
"AjaxLoadingPanelMain"
/>
</
updatedcontrols
>
</
telerik:ajaxsetting
>
</
ajaxsettings
>
</
telerik:radajaxmanager
>
3. Finally, on the code-behind, I've added the following event handler:
Private
Sub
ListBoxSource_Transferred(
ByVal
sender
As
Object
,
ByVal
e
As
Telerik.Web.UI.RadListBoxTransferredEventArgs)
Handles
ListBoxSource.Transferred
ListBoxSource.Items.Sort()
End
Sub
I hope this was what you want and you get it working soon...
Best,
Quattro Formaggi

PERFECT



<
telerik:RadListBox
ID
=
"RadListBox1"
runat
=
"server"
Height
=
"100px"
Width
=
"250px"
DataSourceID
=
"AssetTypesObjectDataSource"
DataTextField
=
"Name"
DataValueField
=
"ID"
TransferToID
=
"RadListBox2"
AllowTransfer
=
"True"
AllowTransferOnDoubleClick
=
"True"
SelectionMode
=
"Multiple"
OnClientTransferred
=
"onClientTransferred"
AutoPostBackOnTransfer
=
"true"
>
<
ButtonSettings
TransferButtons
=
"All"
/>
</
telerik:RadListBox
>
<
telerik:RadListBox
ID
=
"RadListBox2"
runat
=
"server"
Height
=
"100px"
Width
=
"250px"
SelectionMode
=
"Multiple"
>
</
telerik:RadListBox
><
br
/>
<
asp:RequiredFieldValidator
ID
=
"RequiredFieldValidator2"
runat
=
"server"
ErrorMessage
=
"Content Type is a required field."
Text
=
"Content Type is a required field."
ControlToValidate
=
"RadListBox2"
></
asp:RequiredFieldValidator
>
The error occurs when a submit button is clicked from within an <asp:UpdatePanel>.
Try setting the CausesValidation property of both listboxes to false.
All the best,
Bozhidar
the Telerik team

I've attached the sample page I used to test the scenario. It is working fine on my end. Could you verify that the problem reproduces when you run the page on your end.
All the best,
Bozhidar
the Telerik team


What JavaScript options do we have to force update of the radlistbox?
Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. |
Stack Trace:
|
If you are using the example page from my last reply, could you clarify which version of the controls you are using and the exact steps to reproduce the issue? Also if you've made some modifications to it, could you share them so that we can properly reproduce the issue locally?
Regards,
Bozhidar
Telerik

Could you share your implementation of the listbox, so that we can give you a more specific answer? It would be most usefull if you could create a simplified sample project that we can inspect locally.
Regards,
Bozhidar
Telerik

Hi Quattro,
I know this is an old post. I was getting the "Unhandled Exception Index was out of range." as well. To resolve it, I followed much of your code example. The RadListBoxes were placed in a Panel. Added CausesValidation="false" to all RadListBoxes. Added AutoPostBackOnTransfer="true" to all source RadListBoxes. Setup the AjaxManager the same as in your example.
Thanks for providing detailed code to resolve this!
Sincerely,
Keith Jackson

Hi Keith,
Thank you for your post. I'm so glad to hear that an almost 7 years old post still can help people out. I'm not a frequent poster here but kind people like you really encourage more contribution...
Best,
Quattro Formaggi

You're welcome Quattro! Giving credit where credit is due.
Before I found this post, I was removing code to try to find out what was causing the error. It did not make any sense to me why the error was occurring. I have even tried different computers and still got the error. I was almost getting to the point of banging my head on my desk and/or taking a sledge hammer to the computer.
Some of the posts here explained why the error was occurring. I was thinking that made sense as to why the error occurred. I had found another post on a different web site about someone getting the same error with the same situation but there was no solution posted on there. When I was reading through this forum, there was some people that provided something to resolve this error but nothing really detailed. Then I saw your post on this forum and felt that what you posted could work so I tested it with my ASP.Net page. It worked perfectly and the error did not occur. Although the Panel caused my ASP.Net page to look weird at first, I made some adjustments and now it is looking a lot better. Your example code even helped resolve another problem I had when I was trying to get the RadListBoxes on my ASP.Net page to respond a certain way.
Thanks for your help!
Sincerely,
Keith Jackson