Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim btn As New Button()
Dim i As Integer
For i = 1 To 10
btn = New Button()
With btn
AddHandler .Click, AddressOf btnClick
.Text = "button " & i
.Location = New Point(0, i * 60)
.Size = New Size(100, 50)
End With
Controls.Add(btn)
Next
End Sub
Private Sub btnClick(ByVal sender As Object, ByVal e As EventArgs)
MessageBox.Show("You clicked ... " & DirectCast(DirectCast(sender, Button).Text, String))
End Sub
'top of page, inside your class...
Private Panel1 As New System.Web.UI.WebControls.Panel()
Private PlaceHolder1 As New System.Web.UI.WebControls.PlaceHolder()
Private button1 As New System.Web.UI.WebControls.Button()
Private label1 As New System.Web.UI.WebControls.Label()
'inside your Page_Load event...
Controls.Add(PlaceHolder1)
PlaceHolder1.Controls.Add(Panel1)
Panel1.Controls.Add(label1)
Panel1.Controls.Add(button1)
'then you can format the controls once they are added to the form