S
suzy
i thought .net was meant to make things easier, so why is this simple thing
taking me over 2 days.
i have a asp.net page with a checkboxlist control on it. This displays a
bunch of checkboxes. All i want to do is add an onclick event to each
checkbox that calls a javascript function passing in the id of the checkbox.
i could do this easily in classic asp so why is it such a bloody nightmare
in .net?!
to populate the checkboxlist control i call the .DataSource and .DataBind
methods. So I am not doing any explicit looping. However, I have tried
looping through the checkboxlist elements after .DataBind() and manually
call .Attributes.Add it still doesn't work. (see below)
foreach (ListItem item in ((CheckBoxList)
chkList.FindControl("chkList")).Items)
{
item.Attributes.Add ("onclick",
string.Format("javascript:check_Click({0});", item.Value));
}
I don't know if this is the right way to go about things, but the code runs
without errors (and the lines of code are being called when i step through
the code). However, there is no sign of any onclick attriibute on the
client (even if i view source of the html page). it is nowhere in the page.
Someone please help! I am wasting so much time with this.
thank you so much.

taking me over 2 days.
i have a asp.net page with a checkboxlist control on it. This displays a
bunch of checkboxes. All i want to do is add an onclick event to each
checkbox that calls a javascript function passing in the id of the checkbox.
i could do this easily in classic asp so why is it such a bloody nightmare
in .net?!
to populate the checkboxlist control i call the .DataSource and .DataBind
methods. So I am not doing any explicit looping. However, I have tried
looping through the checkboxlist elements after .DataBind() and manually
call .Attributes.Add it still doesn't work. (see below)
foreach (ListItem item in ((CheckBoxList)
chkList.FindControl("chkList")).Items)
{
item.Attributes.Add ("onclick",
string.Format("javascript:check_Click({0});", item.Value));
}
I don't know if this is the right way to go about things, but the code runs
without errors (and the lines of code are being called when i step through
the code). However, there is no sign of any onclick attriibute on the
client (even if i view source of the html page). it is nowhere in the page.
Someone please help! I am wasting so much time with this.
thank you so much.
