Category: Work > ASP.net

C#’s using statement and the K2 API’s

Recently in one of our projects, we had to do some performance optimizations that required us to look a bit closer at the resources our application used. In general, you should always dispose an object that’s implementing the IDisposable interface.

K2’s client API’s use a connection to the K2 server which needs to be closed and disposed after you’re done using them. In C# you can use the using-statement to dispose your objects when you’re done with it. The using-statement only works on objects that inherits from IDisposable.
Here are some examples of how to correctly use the using-statement when using K2 API’s.

Read more »

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

  1. Constructor
  2. OnInit
  3. CreateChildControls
  4. OnLoad
  5. OnPreRender
  6. Render
  7. RenderContents

With consumer/provider:

  1. Constructor
  2. OnInit
  3. CreateChildControl
  4. OnLoad
  5. Provider/Consumer methods
  6. OnPreRender
  7. Render
  8. 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…

  1. Contructor
  2. OnInit
  3. Create child Controls
  4. Onload
  5. Event handling (click!)
  6. Provider/Consumer methods
  7. OnPreRender
  8. Render
  9. 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…

WordPress Themes