In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article introduces the relevant knowledge of "ASP.NET complex attributes and state management example analysis". Many people will encounter such a dilemma in the operation of actual cases, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Complex property declaration / persistence of ASP.NET component design:
The so-called complex attributes are attributes that cannot normally be expressed in the basic data types of CLR. For example, FontInfo, which represents font attributes, contains information such as Bold, Name, Size, Color, and so on (often referred to as sub-attributes).
For complex properties, when a control declares, it usually uses a hyphen of an attribute-subattribute to represent a subattribute of a complex attribute.
< sdp:TextBox id= Textbox1 "Font-Name=" Vender "Font-Size=" 12pt "runat=" server "/ >
The underlined part represents the Font attribute.
Another expression of complex properties is to nest complex properties within the control declaration tag and ride internal property persistence (inner property persistence). Such as:
< asp:DataGrid runat= "Server" > < HeaderStyle ForeColor= "Red" / > < / asp:DataGrid >
Design-time support for complex property serialization / persistence
The design-time implementation is implemented outside the control, using metadata (attribute). For the child properties of hyphen implementation, by setting a specific attribute, you can affect the designer to achieve design-time support.
DesignerSerializationVisibility actually refers to the property class of DesignerSerializationVisibilityAttribute in ASP.NET, specified in metadata, and set to:
DesignerSerializationVisibility.Content lets designers know that the contents of complex properties should be serialized rather than the property itself
DesignerSerializationVisibility.Hidden makes the designer ignore properties and property contents
DesignerSerializationVisibility.Visible lets the designer serialize in a normal way
The so-called normal way is to pass in characters and integers to persist attributes in bytes if they don't belong to them (of course, it's not worth it for complex attributes).
NotifyParentProperty (true) means that changes made by the property browser to this complex property of the control can be notified to the control and that the objects above (usually to the designer application) are told that the property is "dirty". These conventions are important for control designers and designer developers, as well as for developers of ASP.NET pages.
For label-nested property persistence, ParseChilren (true) should be used to specify property persistence, while designer implementation should specify PersistChildren (false) to allow the designer to convert nested tags into part of complex properties (rather than embedded child controls).
Type converter for ASP.NET component design
In order to understand that the persistent form of complex attributes is the design run-time form, it is necessary to specify a type converter for the complex attributes. The basic goal is to convert the persistent form interpretation to the types supported by CLR, and to express the CLR type of the attribute as the design-time and run-time persistent form. Convert Font-Size= "8pt" to 8 of int32 and persist 8 of complex attributes to Font-Size= "8pt".
The implementation of the type converter does not depend on any user interface functionality. Therefore, you can apply the same type converter in both Windows forms and Web forms.
The type converter inherits from System.ComponentModel.TypeConverter.
To implement a type converter for an ASP.NET component design:
1. Define a class that derives from System.ComponentModel.TypeConverter.
Override the CanConvertFrom method to specify the type from which the converter can be converted. This method is overloaded.
3. Rewrite the ConvertFrom method to realize the transformation. This method is overloaded.
Override the CanConvertTo method to specify the type to which the converter can be converted. Converting to a string type does not require this method to be overridden. This method is overloaded.
5. Rewrite the ConvertTo method to realize the transformation. This method is overloaded.
6. Override the IsValid method that performs validation. This method is overloaded.
Determine that a property is associated with a particular type converter by TypeConverter (typeof (somecustimoziedTypeConverter)).
For ASP.NET applications, how to maintain the complex properties of controls between two pages is very important. The default state management of the Control class is left to the ViewSatte dictionary, while complex properties are not possible when using ViewState, which must use the IstateManager interface to participate in state management.
Interface IstateManager {public bool IsTrackingViewState; / / when implemented by a class, gets a value indicating whether the server control is tracking its view state changes. Void LoadViewState (object state); / / when implemented by a class, loads the control view state previously saved by the server control. Object SaveViewState (); / / saves the view state changes of the server control to Object when implemented by the class. Void TrackViewState (); / / when implemented by a class, instructs the server control to track its view state changes. }
The ViewSatte attribute of the Control,Control designed by the ASP.NET component is actually a complex attribute, which is essentially a dictionary class that participates in state management by implementing the IstateManager interface (details of ViewState):
1. The data type of ViewState is the complex attribute System.Web.UI.StateBag class. A dictionary that implements the IstateManager interface. Save multiple key / value pairs, the key is a string, the value is the object, when an object is automatically added to the State instance, that is, ViewState, automatically add a StateItem object, there are actual attribute values and related Boolean marks, knowledge of this attribute (StateItem) has been modified after initialization.
2. Correspond the value of this function to the internal Boolean variable of StateBag in the TrackViewState of the API. If true, when StateItem is added (tracking the ViewState of an object), or when the behavior is modified, StateItem is marked as modified.
3. In SaveViewSate, enumerate the project, create and return two ArrayList to mark the modified key and value, respectively.
4. LoadViewSatet performs the reverse operation of SaveState.
When a property is saved in ViewSatte, its state is automatically maintained. Any number of data needed for disaster reduction round trip transmission can be saved in ViewState (instead of all data, redundant data is eliminated for efficiency), and any data stored in ViewState red is serialized through LosFormatter when necessary.
The state preservation of all complex attributes should implement IstateManager to transform complex attributes into simple attributes that can be saved in ViewState, and can also be combined into complex attributes from simple attributes saved in ViewState.
This is the end of the content of "ASP.NET complex attribute and state management example analysis". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.