CheckBoxList not holding values

S

SA

Hi all,

I am using a checkbox list. The items are populated from a database.

Between postbacks, the items the user selected are not saved. ViewState is
enabled for the control.

In the handling of the postback, I change the checkbox list from
enabled=False to enable=True (the user clicks an "Edit" button on the form,
which has to enable the list, the "Save" button disables the list again).

What can I check to make sure that the selections are retained between
postbacks?
 
G

Guest

Sounds like you are referencing the control BEFORE it is built based on the
database. For view state to map up everything the controls have to exist
(i.e. ListItems). Call your method to bind the check box items BEFORE you
check the selections that were made.
 
S

SA

David:

Thanks for your reply.

That's what I do... the actual items remain in my list, but their "selection
state" is lost upon postback.

I did a very simple test, where I added a "Fake" button to that form. The
event handler for the Fake button is empty. When I make a selection in my
checkboxlist, and then click the fake button, the selections in the
checkboxlist are lost upon postback.

However, during processing server-side, the selections are there. So,
something goes wrong after my event handlers are called.

I have now solved it differently: reload my selections from the database,
unless the save button was clicked, in which case they get reloaded after
the database update.
 
S

SA

Hi Demetri,

No, I don't think that's the case. I don't rebuild my control at all on a
postback. I have tried adding a simple "Fake" button to my form. There's no
code in the fake button event handler.

When I make a selection, and then click the fake button, the form returns
from the postback with all items deselected. However, my actual items are
there. So the view state seems to remember which items are in the
checkboxlist, but not which ones have been selected.
 

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

Members online

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top