473,386 Members | 1,715 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Adding event attributes to checkbox's in CheckBoxList

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.a...&PostID=430387

Nov 19 '05 #1
1 3282
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...;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?

Nov 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Jim Heavey | last post by:
Trying to figure out the technique which should be used to add rows to a datagrid. I am thinking that I would want an "Add" button on the footer, but I am not quite sure how to do that. Is that...
3
by: JD | last post by:
Hello, I have a problem with checkboxlist inside Repeater (in ASP.NET page). I am able to create Checkboxlist and bind it (inside Repeater_ItemBound - including setting checked/unchecked)....
19
by: Sjaakie Helderhorst | last post by:
Hello, I need to add a Javascript event (onClick) to a servercontrol (asp:checkbox). Checkbox is named 'cbDoMail'. Assumed that 'cbDoMail.Attributes.Add("onClick", "doJavascriptThing()") would do...
5
by: DotNetJunkies User | last post by:
1. i want to populate checkboxlist using javascript only at client side ....how can i do this..by populate word i mean that checkboxes should be checked or unchecked on some condition basis.......
4
by: LU | last post by:
I want to add dropdown boxes based on a databind to a checkboxlist. I database/databind to a checkboxlist but for each checkbox created I want to also create a drop down next to it with some...
3
by: vikram | last post by:
How can i add a user define attribute to each checkbox item in a checkbox list control. I want to add a attribute "Tag". Is it possible
2
by: Hardy Wang | last post by:
Hi, I have a CheckBoxList control in my WinForm C# 2.0, I want to know everytime any checkbox in the list got checked/unchecked. I could not find any event like "CheckedChanged" of CheckBox...
1
by: Jason Hartsoe | last post by:
i've tried to add an onchange event to my checkboxes(created dynamically) chkboxlist.attributes.add("onchange", "dothat();") but it renders the onchange to the table it creates and not to the...
1
by: Jason Hartsoe | last post by:
i've tried to add an onchange event to my checkboxes(created dynamically) chkboxlist.attributes.add("onchange", "dothat();") but it renders the onchange to the table it creates and not to the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.