moving items from one list box to another

K

Kay

Hello,

I have two list boxes on my form, one initially displays with items and the
other displays blank, by clicking a button, it is possible to move items
from one box to another and vice a versa, this works fine. I also have a
dropdown list on the page with autopost back = true, my problem is as
follows: when the user selects an option in the dropdown list the form is
posted back to the server and certain other processing happens, then when
the form redisplays, the items that had been moved between the list boxes
have disappeared. How do I maintain the listboxes on a redisplay?
I need to do an autopostback on the dropdown list. I also have a save button
on the form and I know when the user clicks this, I can retrieve the value
in the listbox by doing a Request.Form("listboxID") on the server, however
the dropdownlist text changed event will occur before the save button is
clicked.

Any idea how I might preserve the users selection in the listboxes when I
present the screen back to them after the dropdown list text changed event?

Any help appreciated.
Thanks,
Kay.
 
K

Kevin Spencer

The problem is that you're using all client-side JavaScript to move the
item. Since the ViewState is not changed, and no event is fired, the server
side knows nothing about it. You have to have some way of informing the
server that a change has been made, and what made it. This can be
accomplished by wiring up a server-side event handler to do a PostBack and
move the data on the server side, or by putting some kind of hidden form
field into your client side that holds the data about the transfer, so that
when the PostBack occurs, your code can update the server-side lists.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
 
C

Coucou à toutes et à tous

Without knowing exactly how your code works, I only have a few simple
things to double check. First, are you writing any code in the Page_Load
method that would always overwrite the settings of your dropdown list?
Next, are you enabling the viewstate for each dropdown list?

Chris

--------------------
 
C

Chris Jackson

What type of controls are you using? Are you using <select> elements or
<asp:ListBox> elements? Are you declaring these in your code behind? If your
Page.Load event handler or your declarative code is defining these elements
in their initial state, then you will need to detect IsPostBack and react
accordingly.
 
K

Kay

Hi Chris,

On the page load event in the code behind file, I populate one of the list
boxes, the other listbox is not filled. I also populate the dropdownlist.
EnableViewState is set to true for both the listboxes and the dropdown list.

I have no problem with the dropdown list, this works fine, my problem is
trying to preserve the contents of the listboxes after the form is posted
back to the server due to the text changed event firing for the dropdown
list. When items are moved between the list boxes they redisplay as they
were originally displayed i.e one listbox displays blank regardless of what
had been moved into it.

Thanks,
Kay.
 
K

Kay

Hi Chris,

I am using ASP controls i.e. ListBox and dropdown list are both asp. All my
controls are declared in the code behind. I am using visual studio.net and
drag these controls on to my form at design time. My problem is when the
form posts back to the server as a result of the text changed event on the
dropdown list, when the screen is redisplayed any items that were moved
between the list boxes are lost i.e. the listboxes display as they
originally did when the page was first displayed.

Thanks,
Kay
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top