Dynamic Checkboxes event handling

Discussion in 'ASP .Net Web Controls' started by Rob C, Jun 26, 2003.

  1. Rob C

    Rob C Guest

    Hi all,

    I am dynamically creating checkboxes and am having trouble getting them to launch the OnCheckedChanged event when they are clicked. I am am getting a Postback event when they are checked or unchecked but that is all.

    Here is the code I am using to create my checkboxes in the Page_load function:
    For i = 0 To 5
    Dim cell As New TableCell()
    Row.Cells.Add(cell)
    Dim cb As New CheckBox()
    cb.ID = "cb" & i
    cb.AutoPostBack = True
    cb.Checked = True
    cb.Attributes.Add("OnCheckedChanged", "cbCheckChanged")
    cell.Controls.Add(cb)
    Next i

    If I add a checkbox to the apsx page manually then it calls the event just fine.

    All help is appreciated.

    Rob C.
     
    Rob C, Jun 26, 2003
    #1
    1. Advertising

  2. Rob C

    Alvin Bruney Guest

    wire your oncheckchanged event to its handler. look at initialize component
    function in the aspx page to get an idea how to do it.
    cb.Check += new eventargs(this.control_checkchanged) roughly

    "Rob C" <> wrote in message news:3efb3f45$...
    Hi all,

    I am dynamically creating checkboxes and am having trouble getting them to
    launch the OnCheckedChanged event when they are clicked. I am am getting a
    Postback event when they are checked or unchecked but that is all.

    Here is the code I am using to create my checkboxes in the Page_load
    function:
    For i = 0 To 5
    Dim cell As New TableCell()
    Row.Cells.Add(cell)
    Dim cb As New CheckBox()
    cb.ID = "cb" & i
    cb.AutoPostBack = True
    cb.Checked = True
    cb.Attributes.Add("OnCheckedChanged", "cbCheckChanged")
    cell.Controls.Add(cb)
    Next i

    If I add a checkbox to the apsx page manually then it calls the event just
    fine.

    All help is appreciated.

    Rob C.
     
    Alvin Bruney, Jun 26, 2003
    #2
    1. Advertising

  3. Rob C

    Rob C Guest

    I apologize if I am not getting what you are saying. There is no code in my InitializeComponent procedure to look at. I attempted different variations of your code line below. The procedure I am trying to call is cbCheckChanged so I used that in the eventargs parenthesis but that didn't work because "new" said I was overriding it and it takes no arguments.

    Here is my code again:
    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Dim Row As New TableRow()
    tblClass.Rows.Add(Row) 'tblClass is my precreated table
    Dim i As Integer
    For i = 0 To 5
    Dim cell As New TableCell()
    Row.Cells.Add(cell)
    Dim cb As New CheckBox()
    cb.ID = "cb" & i
    cb.AutoPostBack = True
    cb.Checked = True
    cb.Checked += New EventArgs(Me.cbCheckChanged(sender, e))
    cb.Attributes.Add("OnCheckedChanged", "cbCheckChanged")
    cell.Controls.Add(cb)
    Next i
    End Sub

    Public Sub cbCheckChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
    Trace.Warn("works here")
    End Sub

    All help is appreciated.


    "Alvin Bruney" <vapordan_spam_me_not@hotmail_no_spamhotmail.com> wrote in message news:...
    > wire your oncheckchanged event to its handler. look at initialize component
    > function in the aspx page to get an idea how to do it.
    > cb.Check += new eventargs(this.control_checkchanged) roughly
    >
    > "Rob C" <> wrote in message news:3efb3f45$...
    > Hi all,
    >
    > I am dynamically creating checkboxes and am having trouble getting them to
    > launch the OnCheckedChanged event when they are clicked. I am am getting a
    > Postback event when they are checked or unchecked but that is all.
    >
    > Here is the code I am using to create my checkboxes in the Page_load
    > function:
    > For i = 0 To 5
    > Dim cell As New TableCell()
    > Row.Cells.Add(cell)
    > Dim cb As New CheckBox()
    > cb.ID = "cb" & i
    > cb.AutoPostBack = True
    > cb.Checked = True
    > cb.Attributes.Add("OnCheckedChanged", "cbCheckChanged")
    > cell.Controls.Add(cb)
    > Next i
    >
    > If I add a checkbox to the apsx page manually then it calls the event just
    > fine.
    >
    > All help is appreciated.
    >
    > Rob C.
    >
    >
     
    Rob C, Jun 27, 2003
    #3
    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. Abhijit Salvi via .NET 247

    Handling events for Checkboxes in Data Grid

    Abhijit Salvi via .NET 247, Mar 11, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    3,300
    jfleeson
    Mar 11, 2005
  2. Per Salmi

    Repeater with Checkboxes, handling CheckedChanged event?

    Per Salmi, Feb 24, 2004, in forum: ASP .Net Web Controls
    Replies:
    3
    Views:
    1,316
    Jeffrey Tan[MSFT]
    Feb 26, 2004
  3. Imran Aziz

    Handling checkboxes in Repeater Control

    Imran Aziz, Aug 6, 2005, in forum: ASP .Net Web Controls
    Replies:
    2
    Views:
    327
    Imran Aziz
    Aug 8, 2005
  4. DylanM

    Dynamic Checkboxes & Event handling

    DylanM, Aug 3, 2004, in forum: ASP General
    Replies:
    8
    Views:
    405
  5. pizzy
    Replies:
    7
    Views:
    198
    pizzy
    Mar 23, 2005
Loading...

Share This Page