AddHandler question

Discussion in 'ASP .Net' started by =?Utf-8?B?Sm9l?=, Mar 6, 2006.

  1. 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,
    --
    Joe
     
    =?Utf-8?B?Sm9l?=, Mar 6, 2006
    #1
    1. Advertising

  2. 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?

    "Joe" <> wrote in message
    news:...
    > 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,
    > --
    > Joe
     
    Marina Levit [MVP], Mar 6, 2006
    #2
    1. Advertising

  3. 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?
    --
    Joe


    "Marina Levit [MVP]" wrote:

    > 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?
    >
    > "Joe" <> wrote in message
    > news:...
    > > 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,
    > > --
    > > Joe

    >
    >
    >
     
    =?Utf-8?B?Sm9l?=, Mar 6, 2006
    #3
  4. That was it. Thanks Marina.
    --
    Joe


    "Marina Levit [MVP]" wrote:

    > 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?
    >
    > "Joe" <> wrote in message
    > news:...
    > > 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,
    > > --
    > > Joe

    >
    >
    >
     
    =?Utf-8?B?Sm9l?=, Mar 6, 2006
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jeffrey A. Voigt

    Help w/AddHandler (Not Firing Off)

    Jeffrey A. Voigt, Aug 10, 2003, in forum: ASP .Net
    Replies:
    3
    Views:
    658
    Natty Gur
    Aug 11, 2003
  2. Natty Gur

    Re: Help w/AddHandler (Not Firing Off)

    Natty Gur, Aug 11, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    445
    Jeff Voigt
    Aug 11, 2003
  3. Kay

    Event AddHandler

    Kay, Feb 3, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    2,199
  4. Craig Buchanan

    AddHandler question

    Craig Buchanan, Feb 12, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    405
    Kevin Spencer
    Feb 12, 2004
  5. =?Utf-8?B?Sm9l?=

    AddHandler question

    =?Utf-8?B?Sm9l?=, Oct 26, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    4,728
    leeeyre
    Jul 8, 2010
Loading...

Share This Page