Adding event attributes to checkbox's in CheckBoxList

D

darkpeace

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 :

example:

Protected WithEvents chkSample As
System.Web.UI.WebControls.CheckBoxList

....
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?
http://www.asp.net/Forums/ShowPost.aspx?tabindex=1&PostID=430387
 

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

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top