I found that some netizens have recently written custom controls, but I am not very familiar with the page lifecycle. Here I translate the section about the lifecycle in Jesse Liberty, and hope to help you.
When the user enters the URL in the browser. A webpage with text, images, and buttons appears. In the text box, she enters the text and clicks the button to submit it. What will happen in the background?
Each request is sent to the web server with a step-by-step response. These steps, from the beginning to the end, constitute a similar life cycle.
When a request is also sent, it is loaded, processed, sent to the user, and uninstalled. from the end of one lifecycle to the end of another lifecycle, it mainly presents HTML to the browser. each step has many available methods and events for you to reload the default page loading settings.
To fully understand the lifecycle of pages and controls, it is necessary to understand how the Page class creates a hierarchical control tree on the Page. Besides some comments and Page commands on the Page, all components on the page are part of the control tree. you can add adding trace = "true" to any page command to view the control tree of the page.
The Page class is the root of the control tree. All controls in the control tree are referenced by the control ID. static text, including spaces, line breaks, HTML tags are represented in the tree using LiteralControls. controls in the tree are strictly hierarchical. at a given level, all controls in the control tree are displayed on the page at the same time.
The following describes the status of each component on the web page in its lifecycle. the first page loading of events in the lifecycle is slightly different from the subsequent page returning. the following figure shows the page cycle.
If the page is loaded for the first time, the lifecycle consists of the following steps:
1. Initialization
The initialization phase is the first phase of any page or control lifecycle. The control tree is constructed in the first phase. The initialization phase is modified by controlling the Init event and OnInit method.
2. Load
Load the user input, and the page control displays the client input data. In the loading phase, you can modify the Load event and OnLoad method.
3. Pre-presentation
In this phase, the Child control is accessed before the output is rendered.
The CreateChildControls method is accessed. If necessary, you can create and initialize the Server Control in the control tree. You can modify it through the PreRender event and OnPreRender.
4. Save view status
The view status is saved to an invisible hidden field on the page. You can use the SaveViewState method to reload the view status.
5 Rendering
Pages and controls are rendered in HTML format. You can reload the Render method. In the Render method, the CreateChildControls method is accessed. If necessary, you can create and initialize server controls in the control tree.
6. Destroy
This is the final stage of the lifecycle. It gives you a chance to clear and release some references to "expensive" resources, such as database connections. You can use the Dispose method to modify them.
After the user submits the page, the lifecycle is:
1. Initialization
Same as loading for the first time.
2. Load the view
The property of the control is loaded by the hidden fields on the submitted page. You can modify the property by reloading the LoadViewState method.
3. Load the returned data
At this stage, data is sent to the server through the POST method. It is necessary to update all view statuses through the LoadPostData method.
Page loading
Same as loading for the first time.
4. Wake up the change event
If the current status is different from the status before submission, the change event is awakened by RaisePostDataChangedEvent, for example, the Text value of TextBox is changed, input is enabled, and so on.
5. process the return event
Specifically, when a user action triggers a callback (such as clicking the submit button), the callback event will be processed in the RaisePostBackEvent method only after all change events are processed.
6. Pre-presentation
Same as loading for the first time.
7. Save view status
Same as loading for the first time.
8 Rendering
Same as loading for the first time.
9 destruction
Same as loading for the first time.