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.
This section provides detailed information about the Web Parts life cycle phases, as shown in the following illustration.
The following main tasks are performed during the initialization phase:
The WebPartManager control subscribes to the control life cycle events.
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.
The following main tasks are performed during this phase:
The following main task is performed during this phase:
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.