Dynamic Control Creation w/Events?

  • Thread starter Thread starter Jeff Voigt
  • Start date Start date
J

Jeff Voigt

I have an ASP.NET web page in which consists of one panel object named
pnlTest. In the Page_Load event I'm adding buttons dynamically like so:

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

'Put user code to initialize the page here

'If Page.IsPostBack Then Return



Dim b As WebControls.Button

b = New Button()

b.ID = "btnTestButton1"

b.Text = "Test Button 1"

pnlTest.Controls.Add(b)

pnlTest.Controls.Add(New LiteralControl("<br>"))

b = New Button()

b.ID = "btnTestButton2"

b.Text = "Test Button 2"

pnlTest.Controls.Add(b)



End Sub



I would like a button click event to fire off when the user clicks on a
specific button so that I may perform some server side code. However, I'm
unaware how I can do this with the given code.

Has anyone done this before?

Thanks,
- Jeff
 
Back
Top