"Life and Death order"
"Installing Sun Tzu"
Part 1ArticleThe beginning of this article describes a lot of void theories. I will first talk about the things that are "Big and changed": 1. The details of the life cycle of the Asp.net control (including the page itself; 2. How to Write a control.
"Life and Death order"
Asp.net ProcessingProgramAfter receiving a page request from a user, how does one perform a magic trick to present a fresh page to the client? What has it done? In what order?
To illustrate this problem, we must first understand that a page is also a control. From the perspective of the design pattern, the page model is a "composite", which is a structure tree composed of multiple layers of controls, and the top layer is page, the following controls have leaf branches, and leaf controls do not include sub-controls. Branches are controls that include sub-controls. A method to generate sub-controls is called for each layer of controls, the parent Control calls the generation method of the Child control, and the Child calls Sun's. This recursion ensures that all valid (visible = true) controls on the page are generated, (For details about the design mode, refer to the series of articles on the design mode of Dr. Lu Zhenyu's blog garden. This series of articles is about Dr. Lu's book "Java and mode" (88 yuan, very thick) can at least be used as a quick teaching material for the design model), and each control generally includes the following steps in the lifecycle:
1. instantiate)
Write controls are generally not exposed to this activity.
2. initialize (initialize)
Same as above.
3. Tracking View state )*
This method is important because it involves the view status. In general, you do not need to reload this method.
4. Load view State )*
This method will only be called during the return process. The usage is the same as above.
5. Load PostBack data )*
If your control needs to interact with the client after it is generated, this method is very important and will only be called during the return process.
6. Start loading)
This activity is generally managed only by the onload of the page. Do not use this method when writing controls.
7. There are modifications (raise changed events )*
After the control is generated, the data has been changed by the client, and it is the same as loading and returning data.
8. Raise PostBack event )*
It is generally used to convert client events into server events by controls that implement the ipostbackeventhandler interface. It is only used for the return process.
9. Generate a pre-processing (perrender )**
It is an important process to generate the preliminary work. You can use the onprerender method to implement customization.
10. Save view State )*
If viewstate [XXX] is used to save the information, you do not need to reload it. This method is reloaded only when you manage the custom view status, loadviewstate must be matched with the Save method.
11. Generate (render )***
This is the main character, and the control is basically managed here.
12. Unload)
13. Release (dispose)
Understanding the control lifecycle details is crucial for customizing all components of the control and debugging controls and eliminating control bugs.
Of course, we should pay special attention to some activities in this process. I added the * number behind these activities.
"Installing Sun Tzu"
Do you remember that I mentioned in my previous article that the. NET Framework has done most of the work for us? Indeed, we did not write a control on a tall building. We already have many finished products and semi-finished products. In many cases, in order to quickly develop a control, you can even make your control directly inherit from specific controls such as textbox and button, and make slight modifications to implement your own functions. If this is not a good thing, you 'd better consider inheriting from the following two classes: system. web. UI. control, system. web. UI. webcontrols. webcontrol: the first class is suitable for controls that are not visualized HTML objects, such as controls that generate <meta> <XML> and other content. The second class is suitable for generating various HTML objects, it has implemented basic style management, HTML Tag generation, and other functions.
The next article will discuss all aspects of the control attributes, including the relationship between attributes and the aspx file text of HTML styles, advanced attribute editing methods in Vs and customization of various interaction methods in IDE.