ayha1999
asked on
Table Control
I populate an asp.net table control dynamically in a button click event but it disappears after page postback. how can I keep there after the postback? I have already placed a Table in in the page instead of creating at run time and adding to a place holder.
please help
ayha
please help
ayha
Can you please paste the code, it will help us in understanding the issue.
ASKER
<asp:Table ID="Table1" runat="server">
</asp:Table>
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim tr As TableRow = New TableRow
Dim j As Integer = 0
Do While (j < 10)
Dim tc As TableCell = New TableCell
tc.Text = "date_" & j
tr.Cells.Add(tc)
j = (j + 1)
Loop
Table1.Rows.Add(tr)
End Sub
When I click another button the table disappears.
</asp:Table>
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim tr As TableRow = New TableRow
Dim j As Integer = 0
Do While (j < 10)
Dim tc As TableCell = New TableCell
tc.Text = "date_" & j
tr.Cells.Add(tc)
j = (j + 1)
Loop
Table1.Rows.Add(tr)
End Sub
When I click another button the table disappears.
You need to generate the table on every postback as the table state is not persisted during the postbacks.
In Button_Click save a flag in the viewstate. e.g.
ViewState["gen"]=="y";
And in the page_load check this flag, if its "y" then generate the table again else don't generate it.
In Button_Click save a flag in the viewstate. e.g.
ViewState["gen"]=="y";
And in the page_load check this flag, if its "y" then generate the table again else don't generate it.
ASKER
How can regenerate it in the page load event? please give the code.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks