Found the answer to my own problem. I added a placeholder control to the page, and, instead of using the parent of my button, I add the controls to this placeholder dynamically.
I can then, during oninit, add the number of textboxes previously created.
Code:
Public Class test
Inherits System.Web.UI.Page
Protected WithEvents plhTextBoxes As System.Web.UI.WebControls.PlaceHolder
Protected WithEvents PlaceHolder1 As System.Web.UI.WebControls.PlaceHolder
Protected WithEvents Button1 As System.Web.UI.WebControls.Button
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
End Sub
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Not Page.IsPostBack Then Session("txt") = 0
'Put user code to initialize the page here
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim txtTEMP As New TextBox()
'Dim b As Button = CType(sender, Button)
Session("txt") = Session("txt") + 1
With txtTEMP
.Text = "TextBox " & CStr(Session("txt"))
.ID = "TextBox" & CStr(Session("txt"))
End With
'b.Parent.Controls.Add(txtTEMP)
PlaceHolder1.Controls.Add(txtTEMP)
txtTEMP = CType(PlaceHolder1.FindControl("Textbox" & CStr(Session("txt"))), TextBox)
With txtTEMP.Style
.Add("POSITION", "Absolute")
.Add("LEFT", CStr(Session("txt") * 100) & "px")
.Add("TOP", "500")
.Add("WIDTH", "90")
End With
End Sub
Protected Overrides Sub OnInit(ByVal e As System.EventArgs)
Dim i As Integer
For i = 1 To Session("txt")
Dim txtTEMP As New TextBox()
With txtTEMP
.Text = "TextBox " & CStr(i)
.ID = "TextBox" & CStr(i)
End With
PlaceHolder1.Controls.Add(txtTEMP)
txtTEMP = CType(Page.FindControl("Textbox" & CStr(i)), TextBox)
With txtTEMP.Style
.Add("POSITION", "Absolute")
.Add("LEFT", CStr(i * 100) & "px")
.Add("TOP", "500")
.Add("WIDTH", "90")
End With
Next
End Sub
End Class
Note that, even though I put the "textbox<x>" text in the control's text property (which is plain stupid, of course), the text entered into it appears when rendered, a beautiful demonstration of the LoadViewState event being fired after OnInit (and thus overwriting the here hardcoded textproperty with the saved one
hope this can help others, as it is plain simple :-)