Web Custom Control Problem
This code works fine on a form:
VB Code:
Dim t As New Table
Dim tr As New TableRow
Dim tc As New TableCell
Dim b As New Button
b.Text = "Button 1"
tc.Controls.Add(b)
tr.Cells.Add(tc)
t.Rows.Add(tr)
tr = New TableRow
tc = New TableCell
b = New Button
b.Text = "Button 2"
tc.Controls.Add(b)
tr.Cells.Add(tc)
t.Rows.Add(tr)
PlaceHolder1.Controls.Add(t)
But when I try to do something similar in a Web Custom Control, it doesn't work:
VB Code:
' Page_Load
Dim b As New Button
b.Text = "Button 1"
repeat.Controls.Add(b)
b = New Button
b.Text = "Button 2"
repeat.Controls.Add(b)
VB Code:
' Web Custom Control Render
Protected Overrides Sub Render(ByVal output As System.Web.UI.HtmlTextWriter)
Dim t As New Table
For Each ctrl As Control In Me.Controls
Dim tr As New TableRow
Dim tc As New TableCell
Debug.WriteLine(ctrl.ClientID)
' The next line causes the problem
tc.Controls.Add(ctrl)
tr.Cells.Add(tc)
t.Rows.Add(tr)
Next
t.RenderControl(output)
End Sub
When I use the control on Page_Load, only one button is shown...
Why won't this work?