Dynamically added event handler ignored?

  • Thread starter Thread starter T.
  • Start date Start date
T

T.

Hi group, I am adding an event hander dynamically to a check box inside of
a repeater_itemdatabound method:

Dim chk as CheckBox = CType(e.Item.FindControl("chkIsBilling"), CheckBox)
If Not IsNothing(chk) Then

AddHandler chk.CheckedChanged, AddressOf
IsBillingAddressCheckBox_CheckChanged

End If



here's the handler:

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

'code

End Sub



The event handler is never called...any thoughts? I can fix it by creating
a reference in the aspx to a protected method, i.e.,
OnCheckChanged="ProtectedMethod_CheckChanged". But why doesn't the dynamic
handler work, any thoughts?



Thanks
 
You should also set the AutoPostBack property to true for the event to get
raised in your class.

Hope this helps
Martin
 
At which point are you attaching the handler? Try doing it in the Page_Init
method.

Hope this helps
Martin
 
Back
Top