Table Ignores EnableViewState

Table Ignores EnableViewState

am 27.01.2008 21:46:07 von 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.

--
Jonathan Wood
SoftCircuits Programming
http://www.softcircuits.com

Re: Table Ignores EnableViewState

am 27.01.2008 23:07:45 von forever.zet

On 27 ÑÎ=D7, 22:46, "Jonathan Wood" wrote:
> 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 postbac=
k.
>
> 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 disappear=
s.
> I'm thinking this has something to do with my dynamic data not being store=
d
> in the table's viewstate. But I'm not sure why or what the best workaround=

> is.
>
> Any tips?
>
> Thanks.
>
> --
> Jonathan Wood
> SoftCircuits Programminghttp://www.softcircuits.com

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

Re: Table Ignores EnableViewState

am 28.01.2008 09:07:53 von mark

"Jonathan Wood" wrote in message
news:%23h0nnWSYIHA.5472@TK2MSFTNGP06.phx.gbl...

>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
(in this case, and ) don't survive a postback, and need to be
recreated every time the page loads...

> Any tips?

Use a GridView...


--
Mark Rae
ASP.NET MVP
http://www.markrae.net