Reputation: 603
I have a page base class (.NET4):
public class SitePageBase : System.Web.UI.Page
{
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
}
}
And derived class
public partial class WebsitePage : SitePageBase
{
protected void Page_Load(object sender, EventArgs e)
{
// some processing
}
}
I checked the "Page_Load" in derived class only works if the "base.OnLoad(e)" is there on the base class's OnLoad event handler. Otherwise the "Page_Load" in derived class not get fired at all.
Can any one tell me, why this is happening?
P.S. The AutoEventWireup is set to true.
Upvotes: 0
Views: 4038
Reputation: 19852
Typically the base version of an On<Event>
looks a little bit like this:
protected virtual void OnLoad(EventArgs e)
{
if(Loaded != null)
Loaded(this, e);
}
So in other words, the base member is the one that actually fires the event.
Upvotes: 0
Reputation: 16018
Because you are overriding the behaviour of the base class, and if you don't call base.OnLoad(e)
then the base class will not continue it's implementation (in this case to raise the Load
event)
In your case, if your not doing anything in OnLoad
you can remove the method all together, or as i do remove Page_Load
and do your load login in the overridden OnLoad
These are worth a read
Upvotes: 1
Reputation: 124746
Because the base implementation of the OnLoad method fires the event that is handled by Page_Load
Upvotes: 0
Reputation: 86768
Clearly it's the base's OnLoad
function that raises the Load
event. If you don't call the base's OnLoad
function, the Load
event doesn't get raised, and your Page_Load
event handler never gets invoked.
Upvotes: 0