Newbie question about Checkbox list

G

G

I'm still a newbie not only with .NET, but also with the whole concept of
postbacks and states.

I have a checkbox list with 5 items, all initialized as selected. I have a
button that when clicked, disabled the entire checkbox list. When the very
same button is clicked a second time, the checkbox list is re-enabled.
However, when it is re-enabled, the items all lose their checkmarks.

Can someone in laymen's terms tell me if this is expected behavior? And if
so, how I can maintain the state of the checkbox list when it is disabled
and re-enabled.

TIA,

Brian
 
R

ranganh

Hi,

Where have you initialized and selected the checkboxlist? If you are doing
it in the page_load event, then you need to use the If Not IsPostBack method
to check for the page's state. That is you need to put the code which you
use to popualte the checkboxlist within the If Not IsPostBack ... End If code
block so that It doesnt get populated and loose the selected state each time
a postback occurs.

Sub Page_Load()

If Not IsPostBack

//put your code for populating the checkboxlist and initalizing it

End If

That should solve your problem.

Write back if you have any queries.
End Sub
 
G

G

Thanks for the reply, ranganh, but the problem is actually a quirk in .NET.
For some reason, when checkbox lists are disabled, and then re-enabled, they
lose their state, whereas other simliar controls (like a single checkbox),
do not!

To get around this, I had to store the state of each checkbox list member in
the viewstate before disabling it. Then re-set the states before re-enabling
it.

An adequate work around, but annoying nonetheless.

Brian
 

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

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,151
Latest member
JaclynMarl
Top