Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When creating a web control should you override OnLoad or implement Page_Load

When you create a new web user control in visual studio it by default adds the Page_Load event. What is the advantage to using this rather than overriding the base OnLoad event on the control? Is it just that the Page_Load event fires before OnLoad?

like image 251
Glenn Slaven Avatar asked Sep 28 '08 23:09

Glenn Slaven


3 Answers

The OnLoad method should be the place where the Load event is raised. I personally always try to handle the event unless I need to do extra processing around raising the event.

I recommend handling the event itself under normal circumstances.

like image 110
Adrian Clark Avatar answered Nov 08 '22 17:11

Adrian Clark


You may find this article on the page lifecycle from Microsoft useful.

like image 3
Matt Hanson Avatar answered Nov 08 '22 17:11

Matt Hanson


As you can see above, it does mostly come down to personal choice IF that choice is made knowledgeably. The best quick but solid overview I've seen is at http://weblogs.asp.net/infinitiesloop/archive/2008/03/24/onload-vs-page-load-vs-load-event.aspx

like image 3
Ted Avatar answered Nov 08 '22 17:11

Ted