In an asp.net webforms app I have created a base class for my pages to derive from. I have declared the page load method in the base class as so:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Response.Write("base")
End Sub
Now, in a class that inherits this class, I have used the page load method again:
Protected Shadows Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Response.Write("descendant")
End Sub
For a reason I do not understand, I am seeing both parent and child get written to the page. Both Page_Load methods are being executed. Why is this? I was under the impression that shadowing or overloading a base class method in a descendant class would essentially hide the base class method. I have searched the internet but I cannot find a concrete explanation as to why this is happening.
Thanks,
JS
The
Page_Loadmethod is bound to thePage.Loadevent. If you add aPage_Loadmethod to your subclass, the framework automatically adds this one as a handler in addition to the one of the base class. The code resulting from the precompiler could look somewhat like this, and therefore both methods are being executed once the Load event fires: