Adding event attributes to checkbox's in CheckBoxList

Discussion in 'ASP .Net' started by darkpeace, Jan 18, 2005.

  1. darkpeace

    darkpeace Guest

    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
    darkpeace, Jan 18, 2005
    #1
    1. Advertising

  2. darkpeace

    darkpeace Guest

    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?
    darkpeace, Jan 23, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. JD
    Replies:
    5
    Views:
    11,608
    NetArchitect
    Aug 8, 2007
  2. Patrick.O.Ige
    Replies:
    5
    Views:
    19,059
    Patrick.O.Ige
    Jun 19, 2005
  3. Jerome

    CheckBoxList items attributes : apply CssStyle

    Jerome, Jul 15, 2003, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    1,468
    Victor Garcia Aprea [MVP]
    Jul 16, 2003
  4. Jimmy [Used-Disks]

    CheckBoxList: Adding onclick javascript event to each ListItem.

    Jimmy [Used-Disks], Nov 24, 2003, in forum: ASP .Net Web Controls
    Replies:
    2
    Views:
    693
    Jimmy [Used-Disks]
    Dec 10, 2003
  5. asp123 vbnet via .NET 247

    Adding Checkboxlist/checkbox to dataGrid and retrieving selected value

    asp123 vbnet via .NET 247, Mar 25, 2005, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    603
    asp123 vbnet via .NET 247
    Mar 25, 2005
Loading...

Share This Page