Addhandler with Static Items

  • Thread starter Thread starter Dave H
  • Start date Start date
D

Dave H

I've used AddHandler to add event handling to dynamically create AspX
controls, but I'm having issues assigned a group of static controls the same
way.

This is the code I'm trying:

For nIndex = 1 To nNumberofControls
Try
oCheckBox = FindControl("CheckBox" & nIndex)
oCheckBox.AutoPostBack = True
AddHandler oCheckBox.CheckedChanged, AddressOf HandleProductCheck
Catch ex As Exception
'
End Try
Next

Sub HandleProductCheck(ByVal sender As System.Object, ByVal e As
System.EventArgs)

What am I missing?

Thanks...
 
Dave said:
I've used AddHandler to add event handling to dynamically create AspX
controls, but I'm having issues assigned a group of static controls the same
way.

This is the code I'm trying:

For nIndex = 1 To nNumberofControls
Try
oCheckBox = FindControl("CheckBox" & nIndex)
oCheckBox.AutoPostBack = True
AddHandler oCheckBox.CheckedChanged, AddressOf HandleProductCheck
Catch ex As Exception
'
End Try
Next

Sub HandleProductCheck(ByVal sender As System.Object, ByVal e As
System.EventArgs)

What am I missing?

Thanks...
I'm not familiar with web controls, but your code seems ok to me.

There's one thing to point out which happens at least with WinForms
controls. After you have added your own CheckedChanged event's handler
and if you have already a CheckedChanged event handler, the first
event handler gets called first and only after that your
HandleProductCheck gets called.
 
Back
Top