Search code examples
asp.netpageloadpage-init

page load() or page init()


In asp.net, when do you bind your gridviews? at Page Load() or Page Init()....why?


Solution

  • You should generally bind at or after Load(). The Init() event is intended to allow you to create any dynamically created controls before binding occurrs, so that they exist when binding needs to take place. Load() is not the only option, however...if you need to delay binding on a control for whatever reason, you can also bind in the PreRender() event. It is also possible to do further setup in Load(), call the pages' DataBind() method, and handle the page binding events to bind in an even more structured way, if you need to.