ClientID and Request.form()

  • Thread starter Thread starter cannontrodder
  • Start date Start date
C

cannontrodder

I am writing a composite control that allows two-way binding between a
collection of boolean values and a set of checkboxes.

In the CreateChildControls, I add each checkbox control that I need and
give it a numbered id/name while setting it's checked property as per
the values in my boolean collection.

When I create the control on postback, I pull the datasource out of
viewstate and re-create the checkboxes again with the data source but
at this point I also need to see if any of the checkboxes were changed
on the client and update the datasource as appropriate. I know this
seems odd but it lets me use formview/detailsview to update boolean
data by two-way databinding using the objectdatasource.

Anyway, my question!

The ClientID property of the parent control happens to be
"FormView1_Checklist1_whateverid" so I iterate through the request.form
collection looking for checkboxes that were actually checked. They are
called "FormView1$Checklist1$whateverid".

Am I going to be ok to just replace _ with $ when looking for this
POSTed data or is there another more appropriate way for me to access
posted data?
 
You don't need to replace. UniqueID property returns the ID which is used as
key in POST collection (in Request.Form)

Another thing. If you add them as controls (and recreating on postback
doesn't happen with databinding) they should fire CheckedChanged event in
which you should get which ones were changed.

-
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke
 
Back
Top