Dynamically generated Table Rows Dissappear

B

Bijoy Naick

I have something strange going on.. My .aspx page contains a file upload
control, a "Import Data" button, a "newTransactions" <asp:table>,
a"SaveTrans" button and an confMsg label.

First the user selects a file, then clicks Import Data. The page now reads
the PostedFile and displays each line as a new row in the newTransactions
table. All of this works fine.

For now, I've programmed SaveTrans_Click to display the number of rows in
the newTransactions table in the confMsg label.

When I click on the SaveTrans button, all the rows added dynamically in the
table dissapper and as a result, the congMsg label displays 1 (the header
row I hard coded in the <asp:table> declaration).

What do i need to do to avoid this? Why is this happening?

Thanks.

Bijoy
 
J

Jeffrey Palermo [MCP]

Bijoy,
Understand that dynamic controls have to be created and added to the
page each time the page is built. You are building these table rows in a
post-back event handler, but on the next post-back you aren't building the
rows, so naturally they won't be there after that last post-back. You need
to rethink your page design to make sure that the data for these table rows
can be saved in viewstate and persisted from post-back to post-back.

Best regards,
Jeffrey Palermo
 
B

Bijoy Naick

I "fixed" this by adding the rows to a Session level variable. I was unable
to add a tablerow to ViewState.. Got an error about it not implementing
"Serializable"..

How can I add a tablerow to viewstate?

Thx.

Bijoy
 
J

Jeffrey Palermo [MCP]

Bijoy,
You cannot add objects to viewstate that are not serializable. The
objects that are stored in viewstate can be represented as a string.
TableRow is not one of these. You can store the data for the row in
viewstate, but not the control itself.

--
Best regards,
Jeffrey Palermo
Blog: http://dotnetjunkies.com/weblog/jpalermo


Bijoy Naick said:
I "fixed" this by adding the rows to a Session level variable. I was unable
to add a tablerow to ViewState.. Got an error about it not implementing
"Serializable"..

How can I add a tablerow to viewstate?

Thx.

Bijoy


"Jeffrey Palermo [MCP]" <http://dotnetjunkies.com/weblog/jpalermo> wrote in
message news:[email protected]...
Bijoy,
Understand that dynamic controls have to be created and added to the
page each time the page is built. You are building these table rows in a
post-back event handler, but on the next post-back you aren't building the
rows, so naturally they won't be there after that last post-back. You need
to rethink your page design to make sure that the data for these table rows
can be saved in viewstate and persisted from post-back to post-back.

Best regards,
Jeffrey Palermo

in
the
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,817
Latest member
AdalbertoT

Latest Threads

Top