I have a table that consists of two rows with three cells each row. The cells contain textboxes. I am able to successfully add a new row with textboxes when a button is clicked. The problem is retaining the newly added row with the filled in textboxes on the next button click. I think I am handling my viewstate incorrectly.
This code adds the new row:
Thanks
This code adds the new row:
Code:
Private Sub addRowsInTable() Dim TextID As Integer Dim TextIDCount As String TextID = Int32.Parse(ViewState("rows").ToString()) + 3 TextIDCount = TextID.ToString Dim text As New TextBox() 'Text.AutoPostBack = False Dim cell As New HtmlTableCell() Dim row As New HtmlTableRow() text.ID = "TxtWhat" + TextIDCount text.Attributes.Add("style", "width:371px") cell.Controls.Add(text) row.Cells.Add(cell) text = New TextBox() cell = New HtmlTableCell() text.ID = "TxtWho" + TextIDCount text.Attributes.Add("style", "width:216px") cell.Controls.Add(text) row.Cells.Add(cell) text = New TextBox() cell = New HtmlTableCell() text.ID = "TxtWhen" + TextIDCount cell.Controls.Add(text) row.Cells.Add(cell) tblReasons.Rows.Add(row) ViewState("Rows") = (Int32.Parse(ViewState("rows").ToString()) + 1).ToString End Sub This is where I think I'm messing up. ViewState("rows") shows as 0 when I do a step through. It is not retaining the value from the above sub. Protected Overrides Sub LoadViewState(ByVal savedState As Object) MyBase.LoadViewState(savedState) myRowcount = Int32.Parse(ViewState("rows").ToString()) For i As Integer = 1 To myRowcount Dim text As New TextBox() Dim cell As New HtmlTableCell() Dim row As New HtmlTableRow() text.ID = "TxtWhat" + (i + 3).ToString text.Attributes.Add("style", "width:371px") cell.Controls.Add(text) row.Cells.Add(cell) text = New TextBox cell = New HtmlTableCell() text.ID = "TxtWho" + (i + 3).ToString text.Attributes.Add("style", "width:216px") cell.Controls.Add(text) row.Cells.Add(cell) text = New TextBox cell = New HtmlTableCell() text.ID = "TxtWhen" + (i + 3).ToString cell.Controls.Add(text) row.Cells.Add(cell) tblReasons.Rows.Add(row) Next End Sub
Comment