malek.safa 0 Newbie Poster

hello i need some help trying to loop on the value of my textbox, i have created a place holder and a textbox where i insert a number, and by clicking on the button submit i will have as much as textbox as indicated in the orignal textbox, i have inserted another button that will calculate the summ of the values inserted in the textboxes. the problem is that by clicking on the second button the textbox that are in the place holder will dissapear, any suggestion?

here is my code:
Private Sub btnSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsubmit.Click
Dim I As Integer
For I = 1 To txtnumber.Text
Dim myTextBox = New TextBox
myTextBox.ID = "txtDynamic" & I
myTextBox.Text = "Control Number:" & I
Me.ph1.Controls.Add(myTextBox)
Dim myLiteral = New LiteralControl
myLiteral.Text = "<BR><BR>"
Me.ph1.Controls.Add(myLiteral)
Next


End Sub

Private Sub sum(ByVal cc As ControlCollection)
Dim total As Integer
For Each control As Control In cc
If control.HasControls() Then
sum(control.Controls)
End If

If TypeOf control Is TextBox Then
total += TryCast(control, TextBox).Text
End If
Next
MsgBox(total)
End Sub

Protected Sub btnsumm_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnsumm.Click

sum(Page.Controls)

End Sub