Handling Events for Dynamically Created Controls

Discussion in 'ASP .Net' started by Nathan Sokalski, May 23, 2005.

  1. I have several Button controls that I created dynamically that I need to
    handle the Click events for. How do I specify the event handler for
    dynamically created controls? Thanks.
    --
    Nathan Sokalski

    http://www.nathansokalski.com/
     
    Nathan Sokalski, May 23, 2005
    #1
    1. Advertising

  2. "Nathan Sokalski" <> schrieb
    >I have several Button controls that I created dynamically that I need
    > to
    > handle the Click events for. How do I specify the event handler for
    > dynamically created controls? Thanks.


    Use the Addhandler statement.

    Armin
     
    Armin Zingler, May 23, 2005
    #2
    1. Advertising

  3. "Nathan Sokalski" <> schrieb:
    >I have several Button controls that I created dynamically that I need to
    > handle the Click events for. How do I specify the event handler for
    > dynamically created controls?


    \\\
    Private Sub Test()
    Dim Button1 As New Button()
    With Button1
    .Location = New System.Drawing.Point(56, 88)
    .Name = "Button1"
    .Size = New System.Drawing.Size(144, 48)
    .TabIndex = 0
    .Text = "Button1"
    End With
    AddHandler Button1.Click, AddressOf Me.Button_Click
    Me.Controls.Add(Button1)
    End Sub

    Private Sub Button_Click( _
    ByVal sender As Object, _
    ByVal e As EventArgs _
    )
    MsgBox("Hello World")
    End Sub
    ///

    --
    M S Herfried K. Wagner
    M V P <URL:http://dotnet.mvps.org/>
    V B <URL:http://classicvb.org/petition/>
     
    Herfried K. Wagner [MVP], May 23, 2005
    #3
    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. Mark
    Replies:
    3
    Views:
    521
    Mark Rae
    Jan 8, 2007
  2. Nathan Sokalski
    Replies:
    1
    Views:
    307
    bruce barker
    Feb 27, 2008
  3. msimmons
    Replies:
    0
    Views:
    514
    msimmons
    Jul 16, 2009
  4. Nathan Sokalski

    Handling Events for Dynamically Created Controls

    Nathan Sokalski, May 23, 2005, in forum: ASP .Net Web Controls
    Replies:
    2
    Views:
    129
    Herfried K. Wagner [MVP]
    May 23, 2005
  5. Nathan Sokalski

    Handling events triggered by dynamically created controls

    Nathan Sokalski, Feb 27, 2008, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    131
    bruce barker
    Feb 27, 2008
Loading...

Share This Page