all groups > asp.net > january 2005 >
You're in the

asp.net

group:

Adding event attributes to checkbox's in CheckBoxList



Adding event attributes to checkbox's in CheckBoxList darkpeace
1/17/2005 11:26:35 PM
asp.net: 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
Re: Adding event attributes to checkbox's in CheckBoxList darkpeace
1/22/2005 6:26:17 PM
Bump!! I've searched google groups.. It seams that no one has a good
answer for this one.

There is a reference to this:

http://support.microsoft.com/default.aspx?scid=kb;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"..

Anyone?
AddThis Social Bookmark Button