Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

base.OnLoad(e) in a ASP.NET page

I might have misunderstood the meaning of base.OnLoad(e); My understanding was that this statement will call the OnLoad method of the base class of the class where it's called from. However, when I use the debugger to step through the code, I see different results.

public abstract class BaseUC : System.Web.UI.UserControl
{
   protected override void OnLoad(EventArgs e)
   {
    base.OnLoad(e);

    SomeAbstractMethod();
   }
}

In the ascx.cs concrete class

public partial class MyUserControl : BaseUC
{
    protected void Page_Load(object sender, EventArgs e)
    {
        //On Load logic
    }
}

I have a breakpoint on base.OnLoad(e). When I press F11 (step into), the debugger takes me to Page_Load of MyUserControl, so the flow of control is:

BaseUC.OnLoad()
MyUserControl.Page_Load()
BaseUC.SomeAbstractMethod()

Can someone explain what's going on here?

like image 266
DotnetDude Avatar asked Aug 25 '09 15:08

DotnetDude


1 Answers

  1. BaseUC.Onload calls Control.OnLoad which triggers the Load event.
  2. The Page_Load method works due to AutoEventWireUp=True and executes when the Load event executes.
  3. BaseUC will then continue execution, calling SomeAbstractMethod.
like image 70
sisve Avatar answered Oct 05 '22 13:10

sisve