473,378 Members | 1,209 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

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 2921

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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Ken Varn | last post by:
I have created a custom control that derives from WebControl. The custom control assigns other controls dynamically to the Controls collection. Is there anyway that I can recall the lost of...
3
by: Hadar | last post by:
Hi, I'm still a little bit confused with how managing a webcontrol state over postbacks... Should I use the form's post values to populate the control on the server side when possible, or...
0
by: Matt Howeson | last post by:
I have a problem with a usercontrol that is dynamically loaded, from a web control and is not restoring it's viewstate properly. Here's the scenario. Within our content management system, I have...
0
by: Mike Hofer | last post by:
Hi everyone. I could really use some help. First, the backstory: ===================== I *really* need a 3-state checkbox for my ASP.NET application. Specifically, I need one that lets me set...
1
by: Mike Hofer | last post by:
I have a webcontrol that has the following property defined: <Category("Behavior"), PersistenceMode(PersistenceMode.Attribute),...
0
by: Mythran | last post by:
I have a control that inherits from WebControl. There are 2 properties that react to each other (IE: When you change the value of one property, it modifies the value of the other, and the same...
12
by: Eric Layman | last post by:
Hi, What's the difference between a normal web element: <input type="text" id="txtname" name="txtname" runat="server"> vs webcontrol text box: <asp:Textbox id="username" Columns="10"...
3
by: Tomasz J | last post by:
Hello Developers, How do create a custom WebControl (not UserControl), exposing OnClick event? I reviewed countless examples found by Google, but came across nothing helpful. Below I attach...
0
by: rrutkowski | last post by:
Hi! I have the following situation public class Class1 : WebControl { public Class1() : base(HtmlTextWriterTag.Div) { }
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.