0

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.

user680505
  • 543
  • 1
  • 5
  • 6

5 Answers5

1

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

Community
  • 1
  • 1
Richard Friend
  • 15,800
  • 1
  • 42
  • 60
  • Thank you for the explanation. I am not really doing anything there. so just removed it from the base class. Thanks again – user680505 Mar 29 '11 at 17:40
0

set the AutoEventWireup to false, that solved the problem for me :)

Raul
  • 1
  • 1
0

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.

Gabe
  • 84,912
  • 12
  • 139
  • 238
0

Because the base implementation of the OnLoad method fires the event that is handled by Page_Load

Joe
  • 122,218
  • 32
  • 205
  • 338
0

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.

CodingGorilla
  • 19,612
  • 4
  • 45
  • 65