<input type="checkbox" checked name="myCheckBox" value="helloworld">
What I am trying to do is create a checkbox in the code behind an ASP
and in that code I need to dynamically set the 'value' attribute. NOT
THE CHECKED ATTRIBUTE. I then have some javascript code on that ASP,
which scans all checkboxes in a form, determines which ones are
checked and gets their value. But I don't want the value to be a
simple on/off. I think someone mentioned the use of CheckBoxList, but
I have these checkboxes in a column in a table, and the other columns
have other controls in them, so I'm not sure how I can setup a
checkbox list in between all the other controls. Single checkboxes
give me more flexibility.
Is the 'value' attribute of a checkbox being deprecated or am I
missing something obvious. I cannot believe the CheckBox class does
not have Value as a member. Even setting the value using the
Attributes member does not work.
Can anyone please shed some light on this.
Thanks,
Rob.
Using the Attributes.Add is what you should do. I know you said it didn't
work, but that's really how you should do it...is this how your wrote your
code?
html
<input type="checkbox" checked id="myCheckBox" runat="server">
code-behind
myCheckBox.Attributes.Add("value", "helloworld")
make sure you set the ID and runat="server", otherwise, it won't work from
code-behind.
-Erik Porter
Microsoft .NET MVP
"Rob" <rob...@hotmail.com> wrote in message
news:d9720978.03011...@posting.google.com...
I dynamically create a DataList on a page, which when in edit mode
becomes a form. Actually a lot of my code is dynamic, because I build
a lot of my pages from an xml description and sometimes from database
values. One of the fields on the form has a little help icon next to
it and when the user clicks it, I use some JavaScript to open a new
window, which gives the user a list of possible values to pick from,
with which they can populate the edit field on the calling window's
form. The values displayed are file names, but what is to be returned
to the calling window is the full path and file name. So I thought I'd
display a table with two columns, one column would have the file name
and the other column would have a checkbox. The 'value' of that
checkbox would be the full path and file name, then the user picks
what file they want by checking the checkbox. When the user has made a
selection they click a button called 'Return Selected Items' and
clicking this button calls a JavaScript function that loops over the
selected checkboxes and forms a comma delimited list of the checkbox
values, then sets the text in the edit field of the 'opener' window
with this list. I thought using JavaScript in this way would avoid
submitting forms and reloading pages. I'm just starting out with .Net,
so I'm open to alternate suggestions. Maybe I don't use checkboxes at
all, maybe I let the user select the rows in the selection table, by
changing the row color, but then I need to figure out how to find out
which rows have been selected. I have some more research to do, but
any pointers/help would be most appreciated.
Thanks again,
Rob.
"Erik Porter [.NET MVP]" <erikp...@mvps.org> wrote in message news:<OvpZifFvCHA.2296@TK2MSFTNGP09>...