Dynamically generated Table Rows Dissappear

  • Thread starter Thread starter Bijoy Naick
  • Start date Start date
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
 
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
 
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
 
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

Back
Top