base.OnLoad(五)在ASP.NET页面 [英] base.OnLoad(e) in a ASP.NET page

查看:1551
本文介绍了base.OnLoad(五)在ASP.NET页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可能误会了意思 base.OnLoad(E); 我的理解是,这一声明将调用基类的类的onload方法,其中它的从调用。然而,当我使用调试器逐句通过code,我看到不同的结果。

 公共抽象类BaseUC:System.Web.UI.UserControl
{
   保护覆盖无效的OnLoad(EventArgs的发送)
   {
    base.OnLoad(E);    SomeAbstractMethod();
   }
}

在ascx.cs具体类

 公共部分类的MyUserControl:BaseUC
{
    保护无效的Page_Load(对象发件人,EventArgs的发送)
    {
    //在加载逻辑
    }
}

我对断点base.OnLoad(E)。当我preSS F11(踏入),调试带我到的Page_Load 中的MyUserControl,所以控制流程是:

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

有人能解释这是怎么回事呢?


解决方案

  1. BaseUC.Onload调用Control.OnLoad触发Load事件。

  2. Page_Load方法工程由于AutoEventWireUp = TRUE,当Load事件执行执行。

  3. 然后BaseUC将继续执行,调用SomeAbstractMethod。

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?

解决方案

  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.

这篇关于base.OnLoad(五)在ASP.NET页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆