Web part life cycle

1. OnInit – Valorile configurabile si cele din task pane sunt incarcate in web part.

2. LoadViewState – ViewState-ul web partului este inacarcat acum.

3. CreateChildControls – Toate controalele continute in web part sunt create si adaugate la colectia Controls. Cand pagina este render prima oara aceasta metoda in general are loc dupa OnLoad(). In cazul unui PostBack are loc inaintea lui OnLoad(). Se poate folosi EnsureChildControls() ptr a verifica daca CreateChildControls() a fost apelata. Daca nu a fost apelata o apeleaza acum.

4. OnLoad

5. Evenimente generate de user (Ex. ButtonClick)

6. OnPreRender – aici se pot schimba proprietatile web part-ului inainte de a fi desenat

7. RenderContents – este generat output-ul in format html

8. SaveViewState – ViewState-ul web part-ului este creat, serializat si salvat

9. Dispose

10. UnLoad

Evenimente WebParts

Se foloseste CreateChildControls ptr.
* Instantierea controalelor
* Adaugare evenimente la controale
* Adaugare controale la colectia Controls cu Controls.Add

Se foloseste Render ptr.
* Adaugare logica ptr. a determina daca se face sau nu display la controale
* Render controls folosind control.RenderControl()

OnPreRender:

It is called logically called before Render event of the ASP.NET page.
This is the last opportunity for us to affect the rendering behavior of the web part page.
Things like changes to the viewstate properties can be done logically in the OnPreRender event.  
Moreover the OnPreRender  event is called logically after the events EnsureChildControls and CreateChildControls

CreateChildControls:

If we need to render the ASP.NET web server controls (ike button, text box etc) in the web part,
this event needs to be overridden. Logically we can add web controls and wire the events to it

Render:

This event is used logically to control the rendering behavior of the web part.
There is already a default implementation of Render method.
We need not always override Render method for certain cases
like CreateChildControls method having the logic to add controls.
Render method can be overridden to render both the html stuff and ASP.NET web server controls

Render Control:

This method can be called inside the overridden Render method to render the ASP.NET web server controls
like button, textbox etc…

Render Contents:

RenderContents gives power to render the html streams directly inside the overridden Render method.
The RenderContents should be preceded by RenderBeginTag and the RenderContents should be followed RenderEndTag