Search code examples
c#sharepointdata-bindingsharepoint-2010web-parts

SharePoint 2010 - WebPart - DataBinding - onPageLoad?


A while ago I started working with SharePoint Web Parts (Visual Web Parts). When I was building my first Web Parts I did all my data-binding on PageLoad().

Now I've started to build a custom-filter web part which sends filter-options to another web part through a communication interface. Basically, it works fine but I noticed that the method for receiving the filter-options (ConnectionConsumer) ran after the PageLoad. So if I’m using the filter-web part the DataBinding runs twice (on PageLoad and after receiving the FilterData so the filter can take effect).

So I guess that there is a better place to bind the data to my web part apart from PageLoad.

And now my question: Where should I bind the data?


Solution

  • The rule of thumb is to bind data just before rendering. Override PreRender event instead and do the binding logic there.