Analysis on complex attributes and status management of ASP. NET Component Design

Source: Internet
Author: User

In ASP. NET Component Design, complex attributes and status management are discussed:

Complex attribute Declaration/persistence for ASP. NET Component Design:

The so-called complex attributes are attributes that are usually not expressed using the basic data type of CLR. For example, FontInfo represents a font attribute, which contains information such as Bold, Name, Size, and Color ).

When declaring a complex attribute, the control usually uses the link character of the attribute-subattribute to represent a subattribute of the complex attribute.

 
 
  1. ﹤sdp:TextBox id=”Textbox1” Font-Name=”Vender” Font-Size=”12pt” runat=”server” /﹥ 

The underlined part represents the Font attribute.

Another expression of complex attributes is to nest complex attributes in the control declaration label and ride the inner property persistence ). For example:

 
 
  1. ﹤asp:DataGrid runat=”Server”﹥  
  2.  
  3. ﹤HeaderStyle ForeColor=”Red” /﹥  
  4.  
  5.    ﹤/asp:DataGrid ﹥ 

Support for complex property serialization/persistence design

The implementation is implemented outside the control during design, and is implemented using metadata (attribute. The designer can be influenced by setting specific attributes for the sub-attributes implemented by the hyphen so as to support the design.

DesignerSerializationVisibility actually refers to the attribute class of DesignerSerializationVisibilityAttribute in ASP. NET, which is specified through metadata and set:

DesignerSerializationVisibility. Content allows the designer to know that the Content of complex attributes should be serialized rather than the attributes themselves

DesignerSerializationVisibility. Hidden allows the designer to ignore attributes and attribute content

DesignerSerializationVisibility. Visible allows the designer to serialize in Normal Mode

The so-called normal mode is to use the byte mode for persistent attributes if the character is passed or the integer does not belong to these attributes. Of course, this is quite difficult for complex attributes ).

Policyparentproperty (true) indicates that the property browser can notify the Control of the modification to the complex property of the control and inform the control that the objects above the control will usually be applied to the designer ), it indicates that the property is "dirty. These conventions are important to control designers, designer developers, and ASP. NET page developers.

ParseChilren (true) should be used to specify the persistence of attributes in label nesting mode. If the designer implements nesting mode, PersistChildren (false) should be specified) let the designer convert nested labels into a part of complex attributes rather than Embedded child controls)

ASP. NET component design-type converter

To interpret the persistence form of complex attributes as the design runtime form, you need to specify a type converter for the complex attributes. The basic goal is to convert the persistence form to the type supported by CLR, the CLR type of the attribute is also expressed as a persistent form during design and runtime. Convert Font-Size = "8pt" to 8 of int32, and permanently convert 8 of complex attributes to Font-Size = "8pt ".

The implementation of the type converter does not depend on any user interface function. Therefore, the same type converter can be applied to Windows Forms and Web forms.

The type converter inherits from System. ComponentModel. TypeConverter.

Steps for implementing type converter in ASP. NET Component Design:

1. Define a class derived from System. ComponentModel. TypeConverter.

2. Override the CanConvertFrom method and specify the type from which the converter can be converted. This method is an overload method.

3. Rewrite the ConvertFrom Method for conversion. This method is an overload method.

4. Override the canconvertor method to specify the type that the converter can convert. You do not need to override this method to convert the string type. This method is an overload method.

5. Rewrite the convertor Method for conversion. This method is an overload method.

6. Override the IsValid Method for verification. This method is an overload method.

You can use TypeConverter (typeof (somecustimoziedTypeConverter) to determine whether an attribute is related to a specific type converter.

For ASP. NET applications, it is important to maintain the complex attributes of controls between two pages. The default status management of the Control class is handed over to the ViewSatte dictionary. However, it is impossible to use ViewState for complex attributes. IstateManager must be used for status management.

 
 
  1.  
  2. Interface IstateManager
  3.  
  4. {
  5.  
  6. Public BoolIsTrackingViewState;
  7.  // When implemented by a class,Gets a value that indicates whether the server control is tracking its view status changes. 
  8.  
  9. VoidLoadViewState (ObjectState );
  10. // When implemented by a class, load the view status of the control previously saved by the server control. 
  11.  
  12. ObjectSaveViewState ();
  13. // When implemented by the class, save the view State Changes of the server control to the Object. 
  14.  
  15. VoidTrackViewState ();
  16. // When implemented by a class, it instructs the Server Control to track its view status changes. 
  17.  
  18. }

Control in ASP. NET component design. The ViewSatte attribute of Control is actually a complex attribute, which is essentially a dictionary class. The IstateManager interface is used to manage ViewState details ):

1. The ViewState data type is the complex attribute System. Web. UI. StateBag class. Dictionary that implements the IstateManager interface. Stores multiple key/value pairs. The key is a string and the value is an object. when an object is automatically added to the State object and the instance is called ViewState, A StateItem object is automatically added, there are actual attribute values and related Boolean signs. Knowledge of this attribute StateItem) is modified after initialization.

2. In the TrackViewState of the interface, map the value of this function to the internal Boolean variable of StateBag. If it is true, the ViewState of an object will be tracked when StateItem is added.) or modify the behavior, the StateItem is marked as modified.

3. In SaveViewSate, enumerate the items, create and return two arraylists marked with modified keys and values respectively.

4. LoadViewSatet performs the SaveState inverse operation.

When attributes are saved in ViewSatte, their status is automatically maintained. In ViewState, you can save the required quantity instead of all data for any back-to-back transfer of disaster control and mitigation, and remove redundant data from efficiency considerations ), and any data stored in ViewState red must be serialized through LosFormatter

IstateManager should be implemented to save the status of all complex attributes to convert complex attributes into simple attributes that can be saved in ViewState, and combine simple attributes saved in ViewState into complex attributes.

The complex attributes and status management of ASP. NET components are introduced here. I hope you can learn more about the complex attributes and status management in ASP. NET Component Design.

  1. ASP. NET Server Control
  2. Introduction to ASP. NET Custom Controls
  3. ASP. NET Server Control View
  4. Detailed explanation of the lifecycle of ASP. NET components
  5. Analysis on Transmission Mechanism of ASP. NET Component Design

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.