473,657 Members | 2,513 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_DataBou nd 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 6245
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******** *************@m 73g2000cwd.goog legroups.com...
The situation: I have a CheckBoxList cblTest, the items are disabled in
cblTest_DataBou nd 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.U serControl, and which implements a couple
of functions which basically only are wrappers for built-in functions
like Page.ClientScri pt.RegisterStar tupScript . 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.ClientScri pt.RegisterStar tupScript 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
8068
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 status. David
3
2915
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 occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.NullReferenceException: Object reference not set to an instance...
3
5747
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 list generated, but now there are two problems I haven't been able to overcome: 1) ASP.Net is munging the checkbox ID/Names of the checkboxes: I give it a name like "myCheckbox" and asp.net is creating the checkboxes with the name...
5
13386
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 to get a Boolean value TRUE or FALSE when a checkBox is selected. When the checkBoxList was out of the DataList i used "OnSelectedIndexChanged" and it was returning what i wanted but if its in a
4
4034
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 work:( Thanks My CheckBoxList in the DataList Below
5
1501
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 the original ones. What gives?
0
11000
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 the CheckBoxList control in ASP .NET, I had a hard time figuring out how to dynamically select the items that needed to be selected. Specifically, I was displaying checkboxes for Roles, and I wanted to check the boxes of the roles that were...
1
2002
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 user selects "Checked Baggage" the selection is stored the correct procedure is processed, but if the user selects "SIDA" along with the "Checked Baggage" there is no stored data, just that first selection. Just the first entry is saved. Can...
3
3484
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 checkbox item caused the event to fire to perform some routines based upon the value of that individual checkbox. How can I determine this? For example, 5 of the 10 items maybe checked. However, when I uncheck one, I want to perform some code based...
0
8413
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8324
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8740
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8617
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7352
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5642
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4173
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2742
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 we have to send another system
2
1733
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.