page load() or page init()

Saif Khan picture Saif Khan · Jun 2, 2009 · Viewed 16.7k times · Source

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

Answer

jrista picture jrista · Jun 2, 2009

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.