473,770 Members | 1,841 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

WebControl, CssStyleCollect ion and ViewState

Does anyone know how the Style property of the WebControl class persists
between calls as if it's added to the ViewState? CssStyleCollect ion 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 2939

Hi,

If Style is Control's default style, created in CreateControlSt yle 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 CreateControlSt yle is implemented as follows.

protected virtual Style CreateControlSt yle()
{
return new Style(base.View State);

}

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.128.90...
Does anyone know how the Style property of the WebControl class persists
between calls as if it's added to the ViewState? CssStyleCollect ion 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
251
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 controls that I assigned to my custom control when I receive postback? -- ----------------------------------- Ken Varn Senior Software Engineer Diebold Inc.
3
1900
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 should I always use the viewstate mechanism? For instance, I noticed that the TextBox webcontrol does not depend on the viewstate. I guess it uses the form to retrieve state (the input is submited of course)
0
1536
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 a webcontrol which allows a admin user to select a usercontrol to include within a page when in "edit mode". When a user is editing the page they see a dropdown list of available controls and select one and save the page, kind of irrelevant to...
0
1643
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 the image for the checkbox portion so that the control conforms to my site's visual style, and that lets me set the style for the text in both the enabled and disabled states. As you might expect, I couldn't find one. So I decided to roll my own.
1
1127
by: Mike Hofer | last post by:
I have a webcontrol that has the following property defined: <Category("Behavior"), PersistenceMode(PersistenceMode.Attribute), DesignerSerializationVisibility(DesignerSerializationVisibility.Content)> _ Public Property ForceDeterminateState() As Boolean Get Return CBool(Me.ViewState("ForceDeterminateState")) End Get Set(ByVal value As Boolean) Me.ViewState("ForceDeterminateState") = Value End Set
0
845
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 when you modify the other value, it modifies the first value). So, quick example of my problem. I change Property2 to 12. I view the html source (design-mode). Property2 = 12.
12
3252
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" runat="server"> </asp:TextBox>
3
5710
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 what I got so far. Thank you for any hints. Tomasz J
0
869
by: rrutkowski | last post by:
Hi! I have the following situation public class Class1 : WebControl { public Class1() : base(HtmlTextWriterTag.Div) { }
0
9617
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10254
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10036
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8929
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6710
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5354
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4007
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3607
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2849
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.