By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,703 Members | 1,263 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,703 IT Pros & Developers. It's quick & easy.

Persist table's controls

P: n/a
Hi everyone,

I don't know why all the controls of the Table class (server control)
has to be reconstructed for each page load. The MSDN said that it is
because the children controls are not the Table properties. But why
other controls like ListBox or DataGrid can persist their child
controls?

I'm very confused about this.

Thanks for any reply,

Nhat Yen
Nov 18 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Hi,

all non-controls are persisted via ViewState and they can be restored that
way. But controls do need to recreated on every request (and they then load
their own state indepedently after they have been created)

ListBox works so that it saves the state by calling SaveViewState of its
Items collection (ListItemCollection) which stores the items in key/value
sense. On postback items are loaded from ViewState and ListItemCollection
is reconstructed. E.g ListBox actually uses the similar procedure to
repopulate the collection. ListItems aren't controls so therefore ListBox
can work this way without controls "in the middle".

DataGrid can recreate the controls because they (child controls) are usually
specified in templates (or via columns). DataGrid stores the count of rows
which it uses to recreate the Items collection (by instantiating templates)
and then the child controls load their state independently after they've
been created. So basically DataGrid doesn't store the child controls but
recreates them on postback.

Basically you can't avoid recreating controls because control are themselves
responsible for storing their state. Also it would be terribly inefficient
tho store complete control instances to ViewState, therefore only control
state is stored and controls themselves are recreated.

--
Teemu Keiski
MCP, Microsoft MVP (ASP.NET), AspInsiders member
ASP.NET Forum Moderator, AspAlliance Columnist

"Nhat Yen" <s2******@rmit.edu.vn> wrote in message
news:1d**************************@posting.google.c om...
Hi everyone,

I don't know why all the controls of the Table class (server control)
has to be reconstructed for each page load. The MSDN said that it is
because the children controls are not the Table properties. But why
other controls like ListBox or DataGrid can persist their child
controls?

I'm very confused about this.

Thanks for any reply,

Nhat Yen

Nov 18 '05 #2

P: n/a
Thanks for very clear explanation Teemu, it help me a lot.

Again thank you!

"Teemu Keiski" <jo****@aspalliance.com> wrote in message news:<er**************@tk2msftngp13.phx.gbl>...
Hi,

all non-controls are persisted via ViewState and they can be restored that
way. But controls do need to recreated on every request (and they then load
their own state indepedently after they have been created)

ListBox works so that it saves the state by calling SaveViewState of its
Items collection (ListItemCollection) which stores the items in key/value
sense. On postback items are loaded from ViewState and ListItemCollection
is reconstructed. E.g ListBox actually uses the similar procedure to
repopulate the collection. ListItems aren't controls so therefore ListBox
can work this way without controls "in the middle".

DataGrid can recreate the controls because they (child controls) are usually
specified in templates (or via columns). DataGrid stores the count of rows
which it uses to recreate the Items collection (by instantiating templates)
and then the child controls load their state independently after they've
been created. So basically DataGrid doesn't store the child controls but
recreates them on postback.

Basically you can't avoid recreating controls because control are themselves
responsible for storing their state. Also it would be terribly inefficient
tho store complete control instances to ViewState, therefore only control
state is stored and controls themselves are recreated.

--
Teemu Keiski
MCP, Microsoft MVP (ASP.NET), AspInsiders member
ASP.NET Forum Moderator, AspAlliance Columnist

"Nhat Yen" <s2******@rmit.edu.vn> wrote in message
news:1d**************************@posting.google.c om...
Hi everyone,

I don't know why all the controls of the Table class (server control)
has to be reconstructed for each page load. The MSDN said that it is
because the children controls are not the Table properties. But why
other controls like ListBox or DataGrid can persist their child
controls?

I'm very confused about this.

Thanks for any reply,

Nhat Yen

Nov 18 '05 #3

P: n/a
Thanks for very clear explanation Teemu, it help me a lot.

Again thank you!

"Teemu Keiski" <jo****@aspalliance.com> wrote in message news:<er**************@tk2msftngp13.phx.gbl>...
Hi,

all non-controls are persisted via ViewState and they can be restored that
way. But controls do need to recreated on every request (and they then load
their own state indepedently after they have been created)

ListBox works so that it saves the state by calling SaveViewState of its
Items collection (ListItemCollection) which stores the items in key/value
sense. On postback items are loaded from ViewState and ListItemCollection
is reconstructed. E.g ListBox actually uses the similar procedure to
repopulate the collection. ListItems aren't controls so therefore ListBox
can work this way without controls "in the middle".

DataGrid can recreate the controls because they (child controls) are usually
specified in templates (or via columns). DataGrid stores the count of rows
which it uses to recreate the Items collection (by instantiating templates)
and then the child controls load their state independently after they've
been created. So basically DataGrid doesn't store the child controls but
recreates them on postback.

Basically you can't avoid recreating controls because control are themselves
responsible for storing their state. Also it would be terribly inefficient
tho store complete control instances to ViewState, therefore only control
state is stored and controls themselves are recreated.

--
Teemu Keiski
MCP, Microsoft MVP (ASP.NET), AspInsiders member
ASP.NET Forum Moderator, AspAlliance Columnist

"Nhat Yen" <s2******@rmit.edu.vn> wrote in message
news:1d**************************@posting.google.c om...
Hi everyone,

I don't know why all the controls of the Table class (server control)
has to be reconstructed for each page load. The MSDN said that it is
because the children controls are not the Table properties. But why
other controls like ListBox or DataGrid can persist their child
controls?

I'm very confused about this.

Thanks for any reply,

Nhat Yen

Nov 18 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.