Wednesday, July 18, 2012

Web Part Life Cycle

Web Part Life Cycle
  1. OnInit: Controls Initialization (happens earlier in the lifecycle - view state changes have not been done yet and tracking of it has not been turned on.)
  2. OnLoad: Occurs when the controls are loaded by the page load event.
  3. CreateChildElement: Create any child controls that controls contain.
  4. EnsureChildElement : Ensure that CreateChildElement Event is complete. Use this to guarantee that control exist it before referencing it.
  5. OnPreRender :  All controls are fully loaded on the page.
  6. RenderContents : Render Content Inside the Control

OnPreRender
  1. All controls are fully loaded on the page.
  2. VewState is Loaed
  3. All control values are current
  4. ViewState is not saved and can still be changed
  5. Last chance to change the property of the controls
OnPreRender Use
  1. Update any control property based on the other Professionalization properties.
  2. Get data from database
  3. Make web service calls
  4. Connect data binding
  5. Do any stuff that depends on the state and values of child controls 
  6. Registor  RegistorClientScript Block
Editor Parts
  1. Web control to customize the property
To read more about the Editor Parts please read this post.

Please also read SharePoint Web Part Best Practices

No comments:

Post a Comment