ASP.NET Web Parts Life Cycle
When controls from the ASP.NET Web Parts integrated set of controls are included within a Web page, they obey that page's rules; in particular, they operate within the page's life cycle.
A Web page goes through a life cycle in which it performs a series of processing steps. These steps include initialization, control creation, restoring and maintaining state, running event handler code, and rendering. It is important for you to understand the page life cycle and how it applies to Web Parts so you can implement your logic at the appropriate phase in the cycle. In particular, you must familiarize yourself with the page life cycle to properly initialize the Web Parts controls, populate properties with personalization data, and run any behavior logic.
Web Parts Life Cycle Phases
This section provides detailed information about the Web Parts life cycle phases, as shown in the following illustration.
Web Parts Life Cycle
Initialization
The following main tasks are performed during the initialization phase:
The WebPartZone objects register with the WebPartManager control.
The WebPartManager control loads the static WebPart objects.
The WebPartManager control subscribes to the control life cycle events.
The WebPartManager control calls the TrackViewState method for each static WebPart object already in the control hierarchy at this point.
If you need to programmatically set the properties for a GenericWebPart control, you should do it during this phase so that these properties are available at the proper time, for example when personalization is loaded.
Initialization Complete
The following main tasks are performed during this phase:
The WebPartManager control loads the dynamic WebPart objects and the WebPartConnection objects.
Note
When the WebPartManager control loads the dynamic WebPart objects, each of them must be brought to the same state conditions in which the other parts are. This synchronization causes the TrackViewState method to be called on each dynamic WebPart object.
The WebPartManager control calls the WebPartPersonalization control on the static and dynamic WebPart objects.
Load Complete
The following main task is performed during this phase:
- The WebPartManager control activates the WebPartConnection objects.
Note
During the load complete phase, you can set the values of properties that are not marked as personalizable. At this stage, the WebPartManager control performs some final initialization on the Web Parts controls it manages.
Save State Complete
The following main tasks are performed during this phase:
The WebPartManager control extracts the personalization information from the static and dynamic WebPart objects.
The WebPartManager control saves the static and dynamic WebPart objects' personalization information in permanent storage.
See Also
Tasks
Walkthrough: Creating a Web Parts Page
Reference
Web Parts Control Set Overview
System.Web.UI.WebControls.WebParts
Concepts
Web Parts Personalization Overview