Today you write controls yet? ----ASP.net Control Development Series (two)

Original link: http://www.cnblogs.com/think/archive/2005/05/08/150604.html

"Life and Death orderly"
"loaded loaded grandson"
 on the article "begins," said a lot of empty theory, this article I first talk about "bold aesthetic" of things: 1, ASP.net controls (including page details itself) of the life cycle; 2, how to start a control preparation.
"Orderly life and death"
 of ASP.net handler after receiving a user's page request, it is how to juggle a fresh page presented to the client it? It has done what things? In what order do?
 To illustrate this problem, we must first understand that a page which is itself a Control. From the perspective of design patterns, page model is a "synthetic mode (Composite)", which itself is a tree structure composed of multiple layers of controls, the top layer is Page, the following has leaves and branches, leaves are no longer bear the child controls controls, and bear with control sticks is child controls, the method generates will call each layer controls a generation of child control, call the parent control method of generating child controls, son and grandson of calls, so recursive, ensure that all valid pages the (under normal circumstances is Visible = true) controls have been generated during the processing, something (about the design patterns you can see the Lv Zhenyu teacher design patterns series of articles in the blog Park, this series is Yan Boshi "Java and model," a books (88 yuan, very thick) of refining and processing, materials design pattern can be used for at least a shallow level of crash), but in the life cycle of each control generally includes the following steps:

LifeCycle.jpg

1. instantiated (instantiate)
we write Do not touch the controls in general this activity.
2. Initialize (Initialize)
above.
3. Tracking view (Tracking View State) *
this is more important, to the view state, generally without having to override this method.
4. Load view state (Load view state) *
only call this method in the return process, use ibid.
5. Load return data (Load postback data) *
To interact with clients and if you control after generation, this method is very important, this method is called only return process.
6. Start loading (Load)
This event generally only Page's OnLoad will go to hell, we generally do not touch the controls to write this method.
7. Edit (Raise changed events) *
after control generation, data changed by the client, and return data is loaded all the way.
8. Return Event Processing (Raise postback event) *
General IPostBackEventHandler used to implement the control interface of the client-side events converted into server-side events. Only for the return process.
9. Build pretreatment (PerRender) **
generate preliminary work, this is a very important process, achieved by overriding OnPreRender custom methods.
10. The view state is saved (Save view state) *
If this information is therefore manner ViewState [xxx] to save, reload is not necessary, since only when the custom view state management override this method, of course, here tampered , LoadViewState Save method and it must be here supporting.
11. Generate (Render) ***
This is the protagonist, born into what controls the basic stuff of the pipe here.
12. unloading (Unload)
13. The release (Dispose)
for details on the life cycle of our custom controls for the various parts as well as debugging controls are essential to exclude controls Bug.
Of course, this process some activities that we pay special attention to, and I added an asterisk behind these activities.
"Equipment installed grandson"
 Remember I said in an article in the .net framework has done most of the things for us? Indeed, we write control is not a high-rise from the ground, we've got a lot of finished products and semi-finished products. In many cases, in order to quickly develop a control, you can even make your own controls directly inherited from TextBox, specific controls like Button, slightly modified, can realize their functions. If there is no such thing, then you may want to consider also inherits from two classes: System.Web.UI.Control, System.Web.UI.WebControls.WebControl, first derived class is suitable for generating HTML is not visual objects controls, such as generating <meta> <xml> control the type of content, the second type adapted to generate various HTML objects, it has managed to achieve the basic style, like HTML tag generation function.

Next intention and we explore all aspects of control properties, including the relationship between the aspx file text attributes and HTML style, the property in VS senior editor methods and custom, and so all kinds of interaction in the IDE.

Reproduced in: https: //www.cnblogs.com/think/archive/2005/05/08/150604.html

Guess you like

Origin blog.csdn.net/weixin_30432179/article/details/94793761