Results 1 to 3 of 3

Thread: button click event

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Mar 2005
    Posts
    107

    button click event

    I'm building a table in the code behind page, adding rows and colums to it, and i added a button into one of the cells.

    Dim button9 As New Button
    cellButtonb.Controls.Add(button9)

    How can i add an event to this button. i tried

    Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click

    End Sub

    but it didnt work


    Thanks

    Kati

  2. #2
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177

    Re: button click event

    Use the AddHandler keyword, i.e.
    VB Code:
    1. Private Sub SomeRoutineAddingTheButton()
    2.    Dim button9 As New Button
    3.    
    4.    AddHandler button9.Click, AddressOf Button9_Click
    5.  
    6.    cellButtonb.Controls.Add(button9)
    7. End Sub
    8.  
    9. Private Sub Button9_Click(ByVal sender As Object, ByVal e As EventArgs)
    10.     ' Do Something Here
    11. End Sub
    Regards,

    - Aaron.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Mar 2005
    Posts
    107

    Smile Re: button click event

    Thanks a lot Aaron!!!


    Kati

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width