Table Ignores EnableViewState

J

Jonathan Wood

I have a table that I dynamically populate by creating cells and rows. The
data comes from a database so I would prefer to have the table store the
data in its viewstate rather than having to repopulate it on every postback.

But it doesn't work. I ensure the table's EnableViewState is true. But
whenever there's a postback and I don't repopulate the table, it disappears.
I'm thinking this has something to do with my dynamic data not being stored
in the table's viewstate. But I'm not sure why or what the best workaround
is.

Any tips?

Thanks.
 
F

forever.zet

I have a table that I dynamically populate by creating cells and rows. The
data comes from a database so I would prefer to have the table store the
data in its viewstate rather than having to repopulate it on every postback.

But it doesn't work. I ensure the table's EnableViewState is true. But
whenever there's a postback and I don't repopulate the table, it disappears.
I'm thinking this has something to do with my dynamic data not being stored
in the table's viewstate. But I'm not sure why or what the best workaround
is.

Any tips?

Thanks.

Hi Jonathan,

One option would be to create cells and rows in page's
CreateChildControls method (you might
store number of rows and cells in page's ViewState, so you can
recreate exactly the same number of rows/cells on postback),
So as soon as you create them in CreateChildControls they will be
recreated on postback and will grab all properties
you have assigned to them initially from ViewState.
You might also need to call EnsureChildControls before you assign/read
cell properties (in Page_Load or smth.).


Thanks,
Sergey Zyuzin
 
M

Mark Rae [MVP]

I have a table that I dynamically populate by creating cells and rows. The
data comes from a database so I would prefer to have the table store the
data in its viewstate rather than having to repopulate it on every
postback.

But it doesn't work. I ensure the table's EnableViewState is true. But
whenever there's a postback and I don't repopulate the table, it
disappears. I'm thinking this has something to do with my dynamic data not
being stored in the table's viewstate.

It's not your dynamic data as such - it's that dynamically added controls
Any tips?

Use a GridView...
 

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,230
Members
46,816
Latest member
SapanaCarpetStudio

Latest Threads

Top