I am not able to retrieve the value of dynamically added text box to table.
Kindly help me to find mistake on this code.


Error

Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information about
the error and where it originated in the code.

Exception Details: System.ArgumentOutOfRangeException: Specified argument
was out of the range of valid values. Parameter name: index

Source Error:


Line 52: Dim txtBox As New TextBox()
Line 53:
Line 54:txtBox = CType(Table1.Rows(1).FindControl ("txtBox1"), TextBox)
Line 55: Response.Write(txtBox.Text)
Line 56:


Source File: c:\inetpub\wwwroot\DragDrop\WebForm2.aspx.vb Line: 54

Stack Trace:


[ArgumentOutOfRangeException: Specified argument was out of the range of
valid values.
Parameter name: index]
System.Web.UI.ControlCollection.get_Item(Int32 index)
System.Web.UI.WebControls.TableRowCollection.get_Item(Int32 index)
DragDrop.WebForm2.Button1_Click(Object sender, EventArgs e) in c:\inetpub\wwwroot\DragDrop\WebForm2.aspx.vb:54

System.Web.UI.WebControls.Button.OnClick(EventArgs e)
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(St ring
eventArgument)
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl,
String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
System.Web.UI.Page.ProcessRequestMain()





Source Code

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 Not Page.IsPostBack Then
Dim IdWidth As New Unit("5%")
Dim QWidth As New Unit("95%")
Dim Height As New Unit("20%")
Dim myARow As New TableRow()
Dim myACell1 As New TableCell()
Dim myACell2 As New TableCell()
Dim myACell3 As New TableCell()
myACell1.Width = IdWidth
myACell2.Width = QWidth
myARow.Cells.Add(myACell1)
myARow.Cells.Add(myACell2)
myARow.Cells.Add(myACell3)
Dim txtBox As New TextBox()
Dim hidtxtBoxValue As New HtmlInputHidden()
Dim hidtxtQW As New HtmlInputHidden()
txtBox.ID = "txtBox" & 1
txtBox.Width = QWidth
myACell2.Controls.Add(txtBox)
Table1.Rows.Add(myARow)

End If

End Sub

Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Handles Button1.Click
Dim txtBox As New TextBox()

txtBox = CType(Table1.Rows(1).FindControl("txtBox1"),TextBox)
Response.Write(txtBox.Text)

End Sub