My noodle had a spark of sentience. I was going through my ASP.NET pages, where I noticed
Hang on, Page_Load is not equal to the name of the class, thus it cannot be the constructor of my class on my aspx.cs page
I have a gut feeling that AutoEventWireup="true"
is responsible for telling the page to, by default, call the protected void Page_Load(object sender, EventArgs e)
method. The problem (and question) is that I do not know how or where I can view which events are wired up to which handlers. I am sure that AutoEventWireup="true"
has this snippet somewhere:
this.Load += this.Page_Load
I am merely seeking to expand my knowledge on this. Where can I see which events are being "wired up" by AutoEventWireup?
Edit
I found the idea after trying to do a virtual constructor call (I made a constructor in my code-behind since I accidentally deleted Page_Load
. Resharper suggested I had to seal the class. I thought that it was uncommon behavior. Double checked another page, and copy pasted my Page_Load
back in. That's how I wonder how the events are actually wired up. How does ASP.NET know it must call Page_Load
?
This is for .NET 4 other frameworks would be slightly different but poking around with Reflector you can find that
TemplateControl
whichPage
andUserControl
both inherit has a private methodGetDelegateInformationWithNoAssert
which wires up these delegates.If you follow the usages of this method up you will see it gets called from
HookUpAutomaticHandlers
and this method only attaches the delegates whenSupportAutoEvents
is true.