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. Advertisements

  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. Advertisements

  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. Advertisements

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. Steve Caliendo

    Event handling of dynamic controls

    Steve Caliendo, Apr 15, 2004, in forum: ASP .Net
    Replies:
    6
    Views:
    772
    Kevin Spencer
    Apr 19, 2004
  2. Colin Ramsay

    Dynamic Datagrid UserControl Event Handling

    Colin Ramsay, Apr 17, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    874
    Colin Ramsay
    Apr 17, 2004
  3. Paul Johnson

    Dynamic Controls Event Handling Problem

    Paul Johnson, Jan 8, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    2,104
    gdray
    Jun 12, 2007
  4. Peter Vermilye

    dynamic button creation with event handling?

    Peter Vermilye, Jun 23, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    883
    Peter Vermilye
    Jun 24, 2005
  5. =?Utf-8?B?RGV2ZWxvcGVyX1NvZnR3YXJl?=

    dynamic user control event handling (VS.NET 2003 Ent)

    =?Utf-8?B?RGV2ZWxvcGVyX1NvZnR3YXJl?=, Nov 28, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    3,787
    =?Utf-8?B?RGV2ZWxvcGVyX1NvZnR3YXJl?=
    Nov 28, 2005
  6. Per Salmi

    Repeater with Checkboxes, handling CheckedChanged event?

    Per Salmi, Feb 24, 2004, in forum: ASP .Net Web Controls
    Replies:
    3
    Views:
    2,040
    Jeffrey Tan[MSFT]
    Feb 26, 2004
  7. DylanM

    Dynamic Checkboxes & Event handling

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