469,945 Members | 2,317 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,945 developers. It's quick & easy.

WebControl, CssStyleCollection and ViewState

Does anyone know how the Style property of the WebControl class persists
between calls as if it's added to the ViewState? CssStyleCollection is
not serializable.

The following scenario leads me to believe it is being stored in
ViewState somehow:
1. Add a TextBox and a Button to a form
2. Have the Button.Click event add value to the TextBox.Style collection
3. Add a breakpoint in the Button.Click event handler immediately before
the code in step #2 is executed
4. Run the page
5. Click the button
6. When the code hits the breakpoint, note the number of TextBox.Style
items (you'll get 4, for example)
7. Allow the code in step #2 to run
8. Check the number of TextBox.Style items again (you'll get 5)
9. Click the button again
10. Repeat step 6 and you'll get 5, leading me to believe ViewState is
being used.

Any ideas? Thanks.
Nov 18 '05 #1
1 2836

Hi,

If Style is Control's default style, created in CreateControlStyle and
accessed via ControlStyle (and typed style members, like BackColor for
example), it uses control's own ViewState collection to store the needed
values. In WebControl CreateControlStyle is implemented as follows.

protected virtual Style CreateControlStyle()
{
return new Style(base.ViewState);

}

If control exposes additional styles in addition to the ControlStyle, their
state management needs to be done customized by overriding TrackViewState,
oadViewState and SaveViewState methods of the control and manually
specifying how state is tracked, loaded and saved.
--
Teemu Keiski
MCP, Microsoft MVP (ASP.NET), AspInsiders member
ASP.NET Forum Moderator, AspAlliance Columnist

"Marri Suliez" <ma*@spam.com> wrote in message
news:Xn**********************************@24.168.1 28.90...
Does anyone know how the Style property of the WebControl class persists
between calls as if it's added to the ViewState? CssStyleCollection is
not serializable.

The following scenario leads me to believe it is being stored in
ViewState somehow:
1. Add a TextBox and a Button to a form
2. Have the Button.Click event add value to the TextBox.Style collection
3. Add a breakpoint in the Button.Click event handler immediately before
the code in step #2 is executed
4. Run the page
5. Click the button
6. When the code hits the breakpoint, note the number of TextBox.Style
items (you'll get 4, for example)
7. Allow the code in step #2 to run
8. Check the number of TextBox.Style items again (you'll get 5)
9. Click the button again
10. Repeat step 6 and you'll get 5, leading me to believe ViewState is
being used.

Any ideas? Thanks.

Nov 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Hadar | last post: by
reply views Thread by Mike Hofer | last post: by
1 post views Thread by Mike Hofer | last post: by
reply views Thread by Mythran | last post: by
3 posts views Thread by Tomasz J | last post: by
reply views Thread by rrutkowski | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.