473,503 Members | 241 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Looping through CheckBoxList items doesn't pick up selected ones when items were disabled

The situation: I have a CheckBoxList cblTest, the items are disabled in
cblTest_DataBound in a foreach (ListItem oItem in cblTest.Items) loop.

I provide a link that calls a client-side JavaScript that enables the
items -- this works perfectly. However, when I then click a LinkButton
that does a postback and I loop through the items on serverside to pick
up the selected ones, it doesn't pick them up. IMHO it seems to loop
though the items as they were saved in the ViewState, not as they were
sent to the server.

The real problem is that the CheckBoxList is inside a UserControl that
is used inside an Atlas UpdatePanel, so my original solution wouldn't
work: I decided to disable the CheckBoxList-items on the clientside,
but of course after the UpdatePanel updates, it doesn't fire that
client-side code again and so the items in the CBL remain enabled
(which shouldn't be) and AFAIK there isn't a way to force it to do so.

IMHO the only "solution" would be if there were a way to force the
code-behind to ignore the viewstate of the CheckBoxList when looping
through the items after a postback, but AFAIK there is no way top do
that (unless I am mistaken).

I've noticed a couple of older posts, dating back to 2004 (!) where
developers describe similar problems. So if this is a bug, why wasn't
it solved? Does anyone have a working workaround?

Tools and technologies used: Visual Studio 2005, asp.net 2.0, C#.

--
BVH

Aug 31 '06 #1
2 6236
the underlying probem is that a browser will not postback a disabled fields.
also checkboxes will only postback their value if checked. thus from the
servers side is impossible to tell a disabled postback from a unchecked
postback of a checkbox.

asp.net solution is to remember (using viewstate) that a control was
disabled at render time and what its value was so it can be restored at
postback.

if you want client script to play with enable/disable you will have to come
up you own solution (usually using a hidden field the client script passes
additional state info to the server) . turn off viewstate support on a
control to disable the standard serverside handling.

-- bruce (sqlwork.com)

"Bart Van Hemelen" <ba************@gmail.comwrote in message
news:11*********************@m73g2000cwd.googlegro ups.com...
The situation: I have a CheckBoxList cblTest, the items are disabled in
cblTest_DataBound in a foreach (ListItem oItem in cblTest.Items) loop.

I provide a link that calls a client-side JavaScript that enables the
items -- this works perfectly. However, when I then click a LinkButton
that does a postback and I loop through the items on serverside to pick
up the selected ones, it doesn't pick them up. IMHO it seems to loop
though the items as they were saved in the ViewState, not as they were
sent to the server.

The real problem is that the CheckBoxList is inside a UserControl that
is used inside an Atlas UpdatePanel, so my original solution wouldn't
work: I decided to disable the CheckBoxList-items on the clientside,
but of course after the UpdatePanel updates, it doesn't fire that
client-side code again and so the items in the CBL remain enabled
(which shouldn't be) and AFAIK there isn't a way to force it to do so.

IMHO the only "solution" would be if there were a way to force the
code-behind to ignore the viewstate of the CheckBoxList when looping
through the items after a postback, but AFAIK there is no way top do
that (unless I am mistaken).

I've noticed a couple of older posts, dating back to 2004 (!) where
developers describe similar problems. So if this is a bug, why wasn't
it solved? Does anyone have a working workaround?

Tools and technologies used: Visual Studio 2005, asp.net 2.0, C#.

--
BVH

Aug 31 '06 #2

Bart Van Hemelen wrote:
The real problem is that the CheckBoxList is inside a UserControl that
is used inside an Atlas UpdatePanel, so my original solution wouldn't
work: I decided to disable the CheckBoxList-items on the clientside,
but of course after the UpdatePanel updates, it doesn't fire that
client-side code again and so the items in the CBL remain enabled
(which shouldn't be) and AFAIK there isn't a way to force it to do so.
I've "solved" this. The .ascx now derives from a custom base class that
derives from System.Web.UI.UserControl, and which implements a couple
of functions which basically only are wrappers for built-in functions
like Page.ClientScript.RegisterStartupScript . By doing it this way,
the disabling/enabling now works 100% on client-side even though I
can't figure out why it didn't when I called
Page.ClientScript.RegisterStartupScript directly from the ascx.

--
BVH

Sep 4 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
8058
by: dm_dal | last post by:
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...
3
2902
by: I am Sam | last post by:
I keep getting the following error message when I try to iterate through a CheckBoxList control: Object reference not set to an instance of an object. Description: An unhandled exception...
3
5713
by: Jack Black | last post by:
Using VS.Net 2k3 to build ASP.Net app with VB code-behind pages... Hi, all! I've been struggling with getting a dynamically-generated CheckBoxList generated. I've finally been able to get the...
5
13374
by: Patrick.O.Ige | last post by:
I'm binding a CheckBoxlist below in the ItemDataBound(the CheckBoxList is in a Datalist) By doing "li.Selected = True" i can see all the checkBoxes are selected. But what i want is to be able...
4
4027
by: Patrick.O.Ige | last post by:
I have a CheckBoxList in a DataList and i'm trying to get item Selected after doing a postBack. I have set my CheckBoxlist AutoPostBack="True" Any ideas what 'm doing wrong? It seems not to...
5
1486
by: Mr. SweatyFinger | last post by:
Hi my checkbox list works great, except when i go to edit the items in the browser. It doesn't save the changes. This routine is supposed to save the newly checked items, instead it saves out...
0
10982
by: jeremy | last post by:
Had a tough time figuring this one out and couldn't find a good solution, so I thought I would post this and hopefully it will help someone out. When using DataBind to dynamically bind a list to...
1
1990
by: Zak | last post by:
Hello, I need some help trying to grab the data selected from a checkboxlist. The checklist is acting like a menu. The first selection is accepted but not the multiple ones. For example is the...
3
3476
by: | last post by:
Hi all, I have a CheckBoxList control which has about 10 items. I have set autopostback=true and also set an eventhandler for OnSelectedIndexChanged. The problem is I want to identify which...
0
7282
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
5581
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5017
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4678
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3168
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3157
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1515
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
738
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
389
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.