Table Ignores EnableViewState

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
Jonathan Wood [ So, 27 Januar 2008 21:46 ] [ ID #1917177 ]

Re: Table Ignores EnableViewState

On 27 =D1=CE=D7, 22:46, "Jonathan Wood" <jw... [at] softcircuits.com> 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
forever.zet [ So, 27 Januar 2008 23:07 ] [ ID #1917178 ]

Re: Table Ignores EnableViewState

"Jonathan Wood" <jwood [at] softcircuits.com> wrote in message
news:%23h0nnWSYIHA.5472 [at] 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, <tr> and <td>) 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
mark [ Mo, 28 Januar 2008 09:07 ] [ ID #1917847 ]
Microsoft » microsoft.public.dotnet.framework.aspnet » Table Ignores EnableViewState

Vorheriges Thema: ASP with ASP.net
Nächstes Thema: About GridView 's key fields