Control control style
Controls ultimately generate HTML code on the client, which can use a rich CSS style. Of course, CSS settings can be performed directly, but ASP.NET provides control developers to programmatically control the way. If there is no special requirements for the style, directly inherit the style function of WebControl, if you need to modify or expand inheritance style features, you need to deeply understand the background knowledge of the control style WebControl's style features all encapsulated in the ControlStyle property (a name STYLE The properties of System.Web.ui.WebControls.Style. All style properties are subtribracuits for the ControlStyle property. WebControl as defined in ControlStyle: Private Style _contentStyle; ...... public Style ControlStyle {get {if (_contentStyle = = null) {_contentStyle = CreateControlStyle (); if (IsTrackingViewState) {((IStateManager) _controlStyle) .TrackViewState ();} Return_ContentStyle;}} We see that controlStyle is read-only attributes, created during the first visit (this idea inherits the JIT scheme of .NET). So what is this CreateControlStyle? Protected Virtual Style CreateControlStyle () {Return New Style (ViewSatte);} It is also available to read ViewState. This way, whether you are defined in the Control Declaration from the .aspx page to be reflected in the access. As a control developer, you can customize the properties of the STYLE, for example, the MyTable control defines a TableControl type, adding tables supported by CellPadding / CellSpaceing. The programming control attribute has three ways: 1. Cover the protected virtual function CreateControlStyle 2, use the ApplyStyle (STYLE S) method to copy the custom properties to the controlled yourself to go to 3, MergeStyle (Style S) merge method to ControlStyle In
We see that the control's ControlStyle attributes and other sub-properties are common statebags. Because the control style is called a configuration function that calls the transmission viewState. In addition, the sub-control is also stored in the same stateebag.
The composite control first clarifies that the composite control is different from the user control because it is compiled, and the user control is deployed in text. But common points are class multiplexies to multiplex their features. Composite controls contain multiple setup controls, multiplexed sub-controls. For example, when the composite control to be written contains TextBox, you don't have to implement the iPostBackDataHandler interface. Composite control can send a child control class or a WebControl class. The key points of the compound are: 1. Reburden the CreateChildControl method to instantiate, initialize the child control, and add the child control into the control tree (add to the control tree to Page to get The life cycle of the control. It is necessary to avoid executing business logic in the OnInit event. 2. Implement the System..web.ui.inamingContainer interface to create a new naming range under the composite control. InamingContainer is just a tag interface, allowing the frame to automatically implement the unique name of the child control. Why do you have to create a child control in the CreateChildControls method? In fact, this is to create sub-controls in order to create any child controls during the control life cycle, and you can use sub-controls to handle tasks such as booph data. To ensure that the child control is created before the code is created, the Controllei defined EnSureChildControls protection method checks the sub-control has been created, and if not created, you can call the CreateChildControls method to create. If the child control is not created before render, then the un created sub-control of Visible for TRUE is called EnSureChildControls by the default sub-control of TRUE. Composition can be reused, but it also brings performance loss (such as sub-control instantiation, etc.). Therefore, you need to trade between performance and ease of use, either composite control, or simply write completely generated controls.
How does the composite control view status work? Control builds a status of tracking, saving, and recovering sub-controls. In the Start Tracking View status phase, Control sequentially calls the TRACKVIERSTATE method of the controls in the Controls collection, track the status of the sub-control. If the child control is added to the Controls in the open state in the parent control, the TrackViewState method is called when adding to a collection. In the save view status phase, Control first calls the SaveViewsate method, by default, the ViewState dictionary SaveViewState is first called. And save the returned object, as the first part of the control view; Next, Control calls SaveViewState, if the returned child control is not empty, then the number of the sub-control is saved in two arraylist in two ArrayList State, used to serialize. In the loading view status phase, Control first calls the LoadViewState method to restore the first part of the previously saved status, next to the Controls to access the Controls collection, load the remaining status into the sub-control, which is generally composed of ArrayList by the number and saving, so Restore the turntable of the control and its sub-control. If you have not created a child control at this stage, then save the status of the sub-control, then use it later until the child control is created, load it to the child control.
Event Bubble ASP.NET Page Framework provides a technique called "event bubbling" that allows child control to spread events along its inclusive hierarchy. Event bubbles allow events to raise events in the control hierarchy, and allows event handler to attach the event handler to the control of the original control and the control of the public bubble. For example: Data Binding Controls (Repeater, DataList, and DataGrid) use event bubbling to open a sub-control (in the project template) command event to a top event. Although the ASP.NET server control in the .NET framework uses the event to bubbit the event (the event data class is derived from the CommandEventArgs), any event defined on the server control can bubbber. The control can participate in the event bubbling by two methods inherited from the base class system.web.ui.control. These two methods are: OnbubbleEvent and Raisebubbleevent. The following code snippet shows the signature of these methods. Protected Virtual Bool OnbubbleEvent (Object Source, Eventargs Args); Protected Void, Eventargs Args; RaisebubbleEvent is implemented by Control and cannot be rewritten. RaisebubbleEvent sends event data to the parent of the control along the hierarchy. To handle or trigger the bubble event, the control must override the OnbubbleEvent method.
Make the controls of the event to perform one of the following three operations. 1. The control does not perform any operation, at which time the event is automatically bubbled to its parent. 2, the control is handled and continues to bubbber events. To achieve this, the control must override OnbubbleEvent and call RaisebubbleEvent from OnbubbleEvent. The following code snippet (Example of Template Data Binding Control) makes events after checking the type of event parameters. protected override bool OnBubbleEvent (object source, EventArgs e) {if (e is CommandEventArgs) {TemplatedListCommandEventArgs args = new TemplatedListCommandEventArgs (this, source, (CommandEventArgs) e); RaiseBubbleEvent (this, args); return true;} return false;} 3, the control stops the event bubbling and triggered and / or handling the event. Starting events require calling to schedule events to listeners. To trigger the bubbling event, the control must override OnbubbleEvent to call the OneventName method that triggers this bubbling event. Controls that cause bubbling events typically open the bubbling events as top events. protected override bool OnBubbleEvent (object source, EventArgs e) {bool handled = false; if (e is TemplatedListCommandEventArgs) {TemplatedListCommandEventArgs ce = (TemplatedListCommandEventArgs) e; OnItemCommand (ce); handled = true;} return handled;}
Temption controls use template controls, control developers can specify all or part of the UI generated via Template. The template is part of the page syntax, which can include static HTML (HTML syntax expressed controls actually a sub-control, but belonging to the LiteralControl control) and the server controls for other literary documents. The template function allows the control data to be separated from it. The template control itself does not provide a user interface (UI). The UI of the control is provided by the page developer through the inline template, which allows page developers to customize the UI of the control. By using templates, the control generates different from the UI, but this UI ability is primarily generating page elements. For example, the REPEATER control, etc. To support templateization, the control must implement the Itemplate interface. The page parser parses the text in the template tag and generates a parsing tree to represent the contents of the template, just like the entire Page. Support Template control needs to be done: 1. Implement the System.Web.ui.inamingContainer interface. This is a tag interface without any method. It can create a new naming range under your control, so that the unique identifier is in the name tree. Public Class TemplatedFirstControl: Control, InamingContainer {...} 2, apply PARSECHILDRENATTRIBUTE to the control, and pass true as a parameter. This can indicate how the page analyzer analyzes the template properties tag when using the control on the ASP.NET page. Step 3 shows how to define a template properties. Note If your control is derived from WebControl, you do not need to apply ParsechIldrenattribute because WebControl has been tagged with this property. [Parsechildren (childrenasproperties = true)] Public class templatedFirstControl: control, inamingContainer {...} 3, one or more properties of the System.Web.ui.Itemplate type. Itemplate has a method Instantiatein that creates controls using the templates provided on the onllide. There is no need to implement instantiatein methods; the ASP.NET page framework provides this implementation. The itemplate property must have a metadata property of the System.Web.ui.TemplateContainerattribute, which inamingContainer control will have an instantiation template. This is explained in step 4. A template attribute is defined as shown below. [TemplateContainer]] Public Itemplate FirstTemplate {...} 4, the parameter for TemplateContainerattribute is the type of container controls you want to instantiate the template. Container controls are independent of template controls that are being created. The reason for having a logical container is that template controls typically have a template that requires repeated instantiation using different data. Have a different container control different from the root template control, enabling multiple such examples possible. The logical container is an instant inamingContainer for the template. This relationship is introduced in more detail in the development template data binding control. Note that the container control itself must implement inamingContainer because it has a sub-control that needs to be named on the page. However, the container is merely a container, and the template content that needs to be explained is not controlled. Public Class FirstTemplateContainer: Control, InamingContainer {...} 5, rewrite the CreateChildControls method to create a child control in the template. This is done by three steps.