I reordered some items in a listbox using Javascript. When I read the items in a postback in the code behind (ASP.NET), the order is in the original order. How do I get the same order as shown in the screen after Javascript manipulation?
views:
231answers:
3Your JavaScript will have to notify the server of the rearrangement using AJAX, and then you have to keep track of order manually. This is fairly trivial, but it does mean regenerating the listbox items each page load instead of relying on the ViewState.
Only the selected items will be posted back to the server, the order will be pulled from the viewstate (which your javascript doesnt change). Im not sure you can do what you want in that way. You might have to have a separate [hidden] field that tells the server what order things are in.
Hey,
Using JavaScript code, you can store the order in a hidden variable (make the hidden variable the server HiddenField variable) and process the ordering when the page posts back to the server. Then, you can clear the items and reorder them appropriately using this sequence of numbers stored in the hiddenfield. This is what the AJAX controls do.