Groups | Blog | Home
all groups > asp.net webcontrols > june 2003 >

asp.net webcontrols : Dynamic Checkboxes event handling


Rob C
6/26/2003 1:45:29 PM
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 =3D 0 To 5
Dim cell As New TableCell()
Row.Cells.Add(cell)
Dim cb As New CheckBox()
cb.ID =3D "cb" & i
cb.AutoPostBack =3D True
cb.Checked =3D 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.

Alvin Bruney
6/26/2003 4:32:47 PM
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

[quoted text, click to view]

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
6/27/2003 8:57:47 AM
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 =3D 0 To 5
Dim cell As New TableCell()
Row.Cells.Add(cell)
Dim cb As New CheckBox()
cb.ID =3D "cb" & i
cb.AutoPostBack =3D True
cb.Checked =3D True
cb.Checked +=3D 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:OM7iLqCPDHA.2316@TK2MSFTNGP11.phx.gbl...
[quoted text, click to view]
AddThis Social Bookmark Button