Dynamic Checkboxes event handling

R

Rob C

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

Alvin Bruney

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

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

Rob C

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,996
Messages
2,570,238
Members
46,826
Latest member
robinsontor

Latest Threads

Top