Wednesday, December 9, 2009

Best place for data-binding

In the last 3 months I was involved in development of ASP.Net websites. All the projects were started when I joined them, so a lot of code was written.
All the data-related modifications were implemented in this manner:

  • make the databinding on page_load event

  • handle control events (button click, checkbox check, ...) and make the databinding after any change


This was confusing, when we have several controls causing events, which was causing to do the same databinding several times.
So a question arised - how to reduce the number of databindings - where to make the dtabinding. And here is my answer: Do all the data-related changes on PreRender stage. This have a lot of good pooints:

  • It runs only once per request

  • It runs after all control events, which ensures, that no more flow-changes will arise.


This was a good solution these projects and hope it will also help some of you.