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

Glenn Slaven picture Glenn Slaven · Sep 29, 2008 · Viewed 8.1k times · Source

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?

Answer

Adrian Clark picture Adrian Clark · Sep 29, 2008

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.