WebPart LifeCycle - Cosumer/Provider trouble
Hi,
Ever made a webpart with a consumer/provider model in it? The system is very nice to work with and to create webparts with, but i did have some trouble handling a button click and using the provider… the WebParts’ lifecycle helps understand! I couln’t find it in msdn and i did some searching, found this blog but that didn’t help mutch since i’ve got a different response when stepping trough all the events…
Without Provider/Consumer
- Constructor
- OnInit
- CreateChildControls
- OnLoad
- OnPreRender
- Render
- RenderContents
With consumer/provider:
- Constructor
- OnInit
- CreateChildControl
- OnLoad
- Provider/Consumer methods
- OnPreRender
- Render
- RenderContents
This means you can’t use the provider inside the CreateChildControl… you can fix that by using the OnPreRender to add stuff… slightly bad there, but do-able… not let’s see how it looks with a button click event on there…
- Contructor
- OnInit
- Create child Controls
- Onload
- Event handling (click!)
- Provider/Consumer methods
- OnPreRender
- Render
- RenderContents
This also means that you can’t use the Provider/Consumer inside the click event! That’s a thing i def. do not like… i fixed this by setting a variable on what to do with the provider, and running that code in the Provider/Consumer methods…
If you ask me, the provider/consumer method should be called after the OnInit and before the CreateChildControl…