AddHandler question

G

Guest

Hello All:

I have coded the following in a webform:

Dim btn As New Button
btn.ID = "btnDynamicCarbonCopies"
btn.Text = " More "

AddHandler btn.Click, AddressOf AddDynamicCarbonCopy

plcContent.Controls.Add(New LiteralControl("<br/>"))
plcContent.Controls.Add(btn)

along with:

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

''code in AddDynamicCarbonCopy

End Sub

plcContent is just a placeholder. The page loads fine, behaves fine,
compiles fine, etc. Everything seems to be just fine. Except that
AddDynamicCarbonCopy never fires when I click the button that I just added.

Can anyone see why?

TIA,
 
M

Marina Levit [MVP]

Do you re-add the button and the handler every time the page loads (not just
the first time)? Are you adding the button in Page_Init or Page_Load?
 
G

Guest

The button is re-added everytime the page loads in the PreRender event.
Nothing is done in Page_Init. Could this be the problem? I'm executing this
code too late?
 
G

Guest

That was it. Thanks Marina.
--
Joe


Marina Levit said:
Do you re-add the button and the handler every time the page loads (not just
the first time)? Are you adding the button in Page_Init or Page_Load?
 

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

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top