AddHandler for CheckBox is not working

R

RA

I have simpe code as follows.

Private sub Page_load.....
FillTable()
End Sub

Private Sub FillTable()

'

Dim a As New CheckBox

a.ID = "chkTest"

AddHandler a.CheckedChanged, AddressOf ChkboxChecked

Dim tCell As New TableCell

tCell.Controls.Add(a)

Dim tRow As New TableRow

tRow.Cells.Add(tCell)

tblTest.Rows.Add(tRow)

End Sub



Public Sub ChkboxChecked(ByVal Sender As Object, ByVal e As
System.EventArgs)

'

Dim lsthold As CheckBox = CType(Sender, CheckBox)

Dim a As String

a = "Test"

End Sub



I have breakpoint in ChkboxChecked procedure and it never gets hit.
 
Y

Yama

Hi


Try the following:

Private iCounter As Int32 = 0

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

Dim i As Int32

For i = 0 To 10

FillTable()

Next

End Sub

Private Sub FillTable()

Dim a As New CheckBox

iCounter += 1

a.ID = "chkTest" + CStr(iCounter)

a.AutoPostBack = True

AddHandler a.CheckedChanged, AddressOf ChkboxChecked

Dim tCell As New TableCell

tCell.Controls.Add(a)

Dim tRow As New TableRow

tRow.Cells.Add(tCell)

tblTest.Rows.Add(tRow)

End Sub





Public Sub ChkboxChecked(ByVal Sender As Object, ByVal e As
System.EventArgs)

Dim lsthold As CheckBox = CType(Sender, CheckBox)

Dim a As String

a = "Test"

End Sub
 
R

RA

Thank you for your help.

I was not setting AutoPostBack to True and that was the reason it was not
hitting the breakpoint.
 

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

No members online now.

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,709
Latest member
AustinMudi

Latest Threads

Top