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
 

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

Back
Top