Checkboxes and NamedValueCollection

G

Glenn Owens

Can someone please explain the rationale behind not putting a checkbox
reference into the postback data collection?

I have a composite control (supporting IPostBackDataHandler) which
populates a DataGrid with dynamic controls (textboxes, labels,
dropdownlists, etc). Until I started to implement support for
checkboxes all of the previous controls are always
represented/available in the postback data collection. - not
checkboxes.

Apparently checkboxes only show up in the collection if they're
checked. Aside from being a frustrating none-to-well documented
"feature" this requires the composite control code to handle
checkboxes differently.

Anyone wishing to shed some insight into this odd feature is welcome.
 
S

Steven Cheng[MSFT]

Hi glenn.owens,


Thank you for using Microsoft Newsgroup Service. Based on your description,
you've made a custom web control which has some entry fields in it, when
posted back to server you retrieve the datas in the entry fields via
"LoadPostData" event? However, you found all entry fields' value can be
retrieved correctly except the checkbox control whose value is avaliable
only when it is checked. Is my understanding of your problem correct?

As for this problem of checkbox, I think it is a natural feature of the
html check box(not particularly for the ASP.NET checkbox control). For
example, in a common html page if you use a html checkbox such as:
<input type="checkbox" value="CheckValue" name ="chkTest" />
When the page is posted to serverside, you can retrieve the checkbox's
value(from request.form or querystring) only if
it is checked. Otherwise, there won't be object in the posted data's
collection which repreresent the checkbox's value. As for your situation,
you retrieve the value in the Custom web Control's "LoadPostData" event,
from the postCollection[postDataKey] collection. In fact the data in the
"postCollection" is just from the Request.Form collection which contains
the client entry fields' value. So if the checkbox is not checked, there
won't be any object which represent its value. Thus, if we need to deal
with checkbox in the event, we need to code different from other controls.

Please check out my suggestion. If you have any questions on it, please
feel free to let me know.


Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
S

Steven Cheng[MSFT]

Hi glenn.owens,

I would like to follow up on this issue and see if any progress has been
made. Were you able to check my reply? Should you have any questions,
please feel free to post here.
Looking forward to your reply!


Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 

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,780
Messages
2,569,610
Members
45,255
Latest member
TopCryptoTwitterChannels

Latest Threads

Top