When creating a new WebForm, Visual Studios creates a Page_Load handler in the code behind as a default, which is cool. So for years, I have always put code for doing things like set properties of controls in Page_Load. Recently, I used Reflector to look at some assemblies written by Microsoft and saw that they have put the same type of logic in a method called OnLoad (which supposedly raises the load event). So I started to wonder, where is the best place really to set the properties of controls, in OnLoad or Page_Load? Or in a different method altogether? And if not Page_Load, why does Studio add that to the code behind?
My final thought: Although I know that putting logic in OnLoad works fine, I will probably stick with Page_Load for now because that’s conventional. I asked the question really to find out if I had been missing out on something new after I started seeing OnLoad come up in other people’s code. Thank you all for your thoughtful answers!
Page_Load is just the autoeventwireup for OnLoad. You would think that it doesn’t make any difference which is used, but I agree with K. Scott Allen at Ode to Code that you should usually only deviate from the norm when you are trying to do something unexpected. Overriding a virtual method like OnLoad suggests that you are trying to do something different such as not calling base.Onload, which most programmers are typically not.