Controls on the fly

I am writing a web application that builds buttons on the fly, then it ties the onclick event to a procedure. From the procedure how do I determine which button was clicked.

ex.

Dim btn(var) As Button
Dim i As Integer
For i = 0 To var
btn(i) = New Button()
btn(i).ID = "bttn" & i.ToString
AddHandler btn(i).Click, AddressOf myEventHandler

Next


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

{if this button was pressed do this }


End Sub

Comments

  • Hi,

    Within your sub...

    sender.Name represents the name of the button clicked

    Hope this helps,

    Chris

    : I am writing a web application that builds buttons on the fly, then it ties the onclick event to a procedure. From the procedure how do I determine which button was clicked.
    :
    : ex.
    :
    : Dim btn(var) As Button
    : Dim i As Integer
    : For i = 0 To var
    : btn(i) = New Button()
    : btn(i).ID = "bttn" & i.ToString
    : AddHandler btn(i).Click, AddressOf myEventHandler
    :
    : Next
    :
    :
    : Sub myEventHandler (ByVal sender As System.Object, ByVal e As System.EventArgs)
    :
    : {if this button was pressed do this }
    :
    :
    : End Sub
    :

  • chris

    Thank you, that worked great!!



    : Hi,
    :
    : Within your sub...
    :
    : sender.Name represents the name of the button clicked
    :
    : Hope this helps,
    :
    : Chris
    :
    : : I am writing a web application that builds buttons on the fly, then it ties the onclick event to a procedure. From the procedure how do I determine which button was clicked.
    : :
    : : ex.
    : :
    : : Dim btn(var) As Button
    : : Dim i As Integer
    : : For i = 0 To var
    : : btn(i) = New Button()
    : : btn(i).ID = "bttn" & i.ToString
    : : AddHandler btn(i).Click, AddressOf myEventHandler
    : :
    : : Next
    : :
    : :
    : : Sub myEventHandler (ByVal sender As System.Object, ByVal e As System.EventArgs)
    : :
    : : {if this button was pressed do this }
    : :
    : :
    : : End Sub
    : :
    :
    :

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories