By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,985 Members | 1,863 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,985 IT Pros & Developers. It's quick & easy.

Adding event attributes to checkbox's in CheckBoxList

P: n/a
Okay i'm at my wits end. I've tried every which way to add a simple
onClick even to checkbox items in my code behind :


Protected WithEvents chkSample As

For Loop i = 0; i++ here

Dim item As ListItem = New ListItem

item.text = "Checkbox 1"
item.value = "1"

'method 1 - Indirect Add of Attribute
item.Attributes.Add("OnClick", "alert('hello world')")

'method 2 - Direct Add of Attribute
chkSample.Items(i).Attributes("onClick") = "javascript:alert('hello')

End Loop


In HTML, and in both cases I see this:
<input id="_ctl0__ctl3__ctl0_chkSample_1" type="checkbox"
name="_ctl0:_ctl3:_ctl0:chkSample:1" />

I want to see this:
<input id="_ctl0__ctl3__ctl0_chkSample_1" type="checkbox"
name="_ctl0:_ctl3:_ctl0:chkSample:1" onClick="alert('hello')"/>

No Build errors on either method.. I know i can setup a individual
check box use the attributes.add() and then use the controls.Add() to
place the code in the relevant area. However that shouldn't be
necessary? Any ideas?

I think this may be related to the following thread as a bug?

Nov 19 '05 #1
Share this Question
Share on Google+
1 Reply

P: n/a
Bump!! I've searched google groups.. It seams that no one has a good
answer for this one.

There is a reference to this:;en-us;Q309338

however it doesn't make sense! This isn't a work around, nor does it
give a good example on how to implement this "work around"..


Nov 19 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.