In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article focuses on "what is the life cycle of ASP.NET pages". Interested friends may wish to take a look at it. The method introduced in this paper is simple, fast and practical. Now let the editor take you to learn "what is the life cycle of ASP.NET pages"?
When the asp.net page runs, the page goes through a life cycle in which a series of processing steps are performed. These steps include initialization, instantiating controls, restoring and maintaining state, running event handler code, and rendering. It is important to understand the page lifecycle because in doing so you can write code at the appropriate stage of the lifecycle to achieve the desired results. In addition, if you want to develop custom controls, you must be familiar with the page life cycle in order to properly initialize the control, populate the control properties with view-state data, and run any control behavior code. The lifecycle of the control is based on the lifecycle of the page, but the page raises more control events than are available in a separate asp.net page. )
General ASP.NET page lifecycle phase
In general, the page goes through the stages outlined in the following table. In addition to the page life cycle phase, there are application phases before and after the request, but these phases are not specific to the page.
Life cycle event
At each stage of the ASP.NET page life cycle, the page raises events that can be handled by running your own code. For control events, you can bind an event handler to an event either by declaratively using properties such as onclick, or by using code.
The page also supports automatic event wiring, that is, asp.net looks for methods with a specific name and runs them automatically when a specific event is raised. If the AutoEventWireup property of the @ Page directive is set to true (or if it is not defined because the property defaults to true), the page event is automatically bound to methods that use the naming convention of the Page_ event, such as Page_Load and Page_Init. For more information about automatic event connections, see the asp.net Web server control event model.
The following table lists the most common page lifecycle events. There are other events in addition to the events listed; however, most page processing schemes do not use these events. Instead, it is mainly used by server controls on asp.net pages to initialize and render themselves. If you want to write your own asp.net server controls, you need to understand these phases in detail.
Other page lifecycle considerations
Each asp.net server control has its own life cycle, which is similar to the page life cycle. For example, the Init and Load events of a control occur during the corresponding page event.
Although Init and Load occur recursively on each control, they occur in reverse order. The Init event (and also the Unload event) for each child control occurs (from bottom to top) before the corresponding event is raised for its container. However, the container's Load event occurs before the Load event of its child control (from top to bottom).
You can customize the appearance or content of a control by handling its events, such as the Click event of the Button control and the SelectedIndexChanged event of the ListBox control. In some cases, you may also need to handle the DataBinding or DataBound event of the control. For more information, see the class reference topics for individual controls and developing custom asp.net server controls.
When you inherit a class from the Page class, you can override methods in the base class of the page in addition to handling events raised by the page. For example, you can override the InitializeCulture method of a page to set culture information dynamically. Note that when you create an event handler using Page_ event syntax, the base implementation is implicitly called, so there is no need to call it in the method. For example, the OnLoad method of the page base class is always called, whether or not the Page_Load method is created. However, if you override the OnLoad method of a page with the override keyword (Overrides in Visual Basic), you must explicitly call the base method. For example, if you override the OnLoad method on a page, you must call base.Load (MyBase.Load in Visual Basic) to run the base implementation.
Catch-up events for added controls
If controls are created dynamically at run time, or declaratively in the template of a data-bound control, their events are initially out of sync with the events of other controls on the page. For example, for controls added at run time, the Init and Load events may occur much later in the page life cycle than the same events for controls created declaratively. Therefore, from the moment of instantiation, the event of a dynamically added control occurs after the event of the control in the template until it catches up with the corresponding event when the control joins the Controls collection.
In general, you don't have to worry about this unless there are nested data-bound controls. If a child control has performed data binding, but its container control has not yet performed data binding, the data in the child control may not be synchronized with the data in its container control. This is especially true if the data in the child control is processed based on the data binding values in the container control.
For example, suppose you have a GridView that displays a company record per line, and a ListBox control that contains a list of company managers. To populate the list of managers, you need to bind the ListBox control to a data source control, such as SqlDataSource, which uses CompanyID to retrieve company manager data in the query.
If the data-binding properties of the ListBox control, such as DataSourceID and DataMember, are set declaratively, the ListBox control attempts to bind to its data source during the DataBinding event that contains the row. However, the CompanyID field of the row does not contain a value until the RowDataBound event of the GridView control occurs. In this case, the child controls (ListBox controls) are bound before the containing controls (GridView controls) are bound, so their data binding phases are not synchronized.
To avoid this, you need to place the data source control of the ListBox control in the same template item as the ListBox control itself, and do not set the data binding properties of the ListBox declaratively. Instead, you should set them programmatically at run time during RowDataBound events, so that the ListBox control will not bind to its data until the CompanyID information is available.
Data-bound events for data-bound controls
To help you understand the relationship between the ASP.NET page life cycle and data-bound events, the following table lists data-related events in data-bound controls such as GridView, DetailsView, and FormView controls.
Login control event
The Login control can use the settings in the Web.config file to automatically manage membership verification. However, if your application requires you to customize how the control works, or if you want to understand how Login control events relate to the page life cycle, you can use the events listed in the following table.
At this point, I believe that you have a deeper understanding of "what is the life cycle of ASP.NET pages?" you might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.