Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Looping through CheckBoxList items doesn't pick up selected ones when items were disabled

Reply
Thread Tools

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

 
 
Bart Van Hemelen
Guest
Posts: n/a
 
      08-31-2006
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

 
Reply With Quote
 
 
 
 
bruce barker \(sqlwork.com\)
Guest
Posts: n/a
 
      08-31-2006
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) 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
>



 
Reply With Quote
 
 
 
 
Bart Van Hemelen
Guest
Posts: n/a
 
      09-04-2006

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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Get selected items from a Multi-Select Listbox without looping through all amypower@gmail.com Javascript 0 01-03-2007 03:47 PM
When to pick quad core and when to pick dual core thingy NZ Computing 6 11-21-2006 07:08 AM
When to pick ASP.Net, when to pick desktop? tom c ASP .Net 5 11-01-2006 06:15 PM
How to get Selected item in a Databinded CheckBoxList when CheckBoxlist is in a DataList? Patrick.O.Ige ASP .Net 5 06-19-2005 06:11 AM
Hard drives--Are big ones more delicate than smaller ones? PowerPost2000 Computer Support 2 03-01-2005 10:30 PM



Advertisments