? Known Issue: CheckBoxList & viewstate

D

dm_dal

Is there a know issue surrounding the CheckBoxList control and it's
viewstate?

When my control is created, it's ListItems are checked as needed, but on a
postback, they loose their Selected status.

David
 
M

Marshal Antony

Hi david,
I use CheckBoxList control a lot and I don't have any problems so far.
Make sure your EnableViewState = true for the control.
Also if you load the items to the control in the
Page_Load event,make sure to put it in if(!Page.Postback){},
otherwise when you post back if you have some other code to populate the
checkboxlist can make loose the selected status .
I don't know your actual problem unless I see some code.Please provide the
sample code you are using with Checkboxlist
and on which events so that I may be able to help you.

Hope this helps.
Regards,
Marshal Antony
..NET Developer
http://www.dotnetmarshal.com
 
M

Marshal Antony

typing mistake if(!Page.IsPostBack){}
Marshal Antony said:
Hi david,
I use CheckBoxList control a lot and I don't have any problems so far.
Make sure your EnableViewState = true for the control.
Also if you load the items to the control in the
Page_Load event,make sure to put it in if(!Page.Postback){},
otherwise when you post back if you have some other code to populate the
checkboxlist can make loose the selected status .
I don't know your actual problem unless I see some code.Please provide the
sample code you are using with Checkboxlist
and on which events so that I may be able to help you.

Hope this helps.
Regards,
Marshal Antony
.NET Developer
http://www.dotnetmarshal.com
 
D

dm_dal

I have checked to make sure Enable ViewState is true. The CheckBoxList is
created in the design view, with all the ListItems being created at that
time. In my "Page_Load" section (and within the if(!IsPostBack) loop, is
where I set the Selected items. So they are not being set anywhere else.

The only thing different that I'm doing is, initially, all the controls on
the page are disabled. There is an edit button that, when the user clicks,
causes a postback and the event handler for that button calls a void that
enables the controls. It's during this postback that the view state for the
CheckBoxList appears to be lost.

I've since gone back and replaced this control with three seperate CheckBox
controls and the viewstate is working fine.

On a side note, I did read a reference to the CheckBoxList yesterday (can't
remember where just now), that indicated that the CheckBoxList control does
not implement ISerializable, so the the viewstate of the embedded ListItems
cannot be serialized and saved during postback situations, the suggested
alternative was to create an ArrayList to hold the state of the individual
ListItems during postback.

But, if you can get it to work for you, then I guess that article was bunk.

David
 
M

Marshal Antony

David,
After testing Checkboxlist with the Enabled property I found that
there is a bug with CheckBoxList control.
I didn't experience the problem in my applications because I was not
disabling and enabling the CheckboxList control.
The testing I have done:
Set the enabled property of the Checkboxlist control to
false.While Page_Load, in !Page.IsPostBack set the Selected property
of an item in the Checkbox.After loading the Webform,click on a button
where the enabled property of the Checkboxlist is set to true,the result is,
that item is unchecked!!. I did the same testing for a list box and it is
preserving the selected property.
May be somebody at Microsoft can help you with this bug.
Hope this helps.
Regards,
Marshal Antony
..NET Developer
http://www.dotnetmarshal.com
 

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,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top