views:

70

answers:

2

I'm working on developing a custom control to select items from a predefined list. This is accomplished via 2 ASP.NET ListBox controls, with a few buttons to trigger the movement of ListItems from one ListBox to the other (lets call these ListBoxes lstSelected and lstDeselected).

This is easy enough to do in ASP.NET or JavaScript independently: I have both working. However, if modifications are made via JavaScript, ASP.NET retains no knowledge of this. Is there any way to register the creation of of options in a select tag without AJAX?

A: 

You could also do this with traditional postbacks, it doesn't have to be ajax. The postbacks would be triggered by clicking your buttons which change which items are in which listboxes.

Matt Dearing
A: 

You could have a couple of hidden fields, say hdnHasSelectedChanged and hdnHasDeselectedChanged, and set those fields in your javascript code. Then, when a postback really happens, your code-behind can read those hidden fields to detect if changes occurred.

Steve Danner
I've tried simulating this by just posting back and assuming that changes have been made, but it hasn't been successful. I think the modification of existing elements, rather than creation of new elements, will be the key for recognition by ASP.NET.One approach I'm contemplating is to treat the control like a specially-rendered CheckboxList, with each ListBox being fully-populated with all options, and hiding the selected items in the ListBox for deselected items, and hiding deselected items in the ListBox for selected items.
Steven