Dynamic Control Creation w/Events?

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
 

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,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top