Fog Creek Software
Discussion Board

Welcome! and rules

Joel on Software

How to handle events for dynamically-added control

Given a page that only contains a place-holder:

<form id="Form1" method="post" runat="server">
<asp:PlaceHolder id="ph" runat="server"></asp:PlaceHolder>

In the page_init, I do:

Dim ph As PlaceHolder
ph = Page.FindControl("ph")
Dim b As New Button

What do I need to do to be able to handle a click on b?

I tried
AddHandler b.Click, New EventHandler(AddressOf Me.bClick)

and just
AddHandler b.Click,AddressOf Me.bClick

but this doesn't seem to work.

Any help, or pointers to somewhere that might explain this, would be appreciated.


Chris F
Monday, February 7, 2005

Does the bClick procedure actually exist?

And does its signature match the required signature for the Click event (which is usually (Sender as Object, e as EventArgs) or something similar)?

Monday, February 7, 2005

Hm...not sure what I did, but it's now working, with either of the AddHandler lines.

Chris F
Monday, February 7, 2005

*  Recent Topics

*  Fog Creek Home