Dynamic Events Question

B

Bishop

Below is the code I'm using. It works as designed but now I want to
determine which of the ten buttons was clicked. Any help on how to do this
is appreciated.

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

Dim x As Int16

For x = 1 To 10

Dim btnAdd As New Button

btnAdd.ID = x.ToString

Page.FindControl("FORM1").Controls.Add(btnAdd)

btnAdd.Text = "Click Me"

AddHandler btnAdd.Click, AddressOf btnAdd_Click

Next

End Sub

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

Response.Write("hello world")

End Sub
 
B

Bishop

Don't you hate it when you look for hours and just after asking you figure
it out... :)

Here is what I did and it worked.

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

Dim myButton As Button

myButton = CType(sender, Button)

Response.Write(myButton.ID)

End Sub
 

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,769
Messages
2,569,577
Members
45,054
Latest member
LucyCarper

Latest Threads

Top