覆盖页面类构造函数在ASP.NET code-隐藏文件 - 当它叫什么名字?叫什么名字、当它、函数、隐藏文件

2023-09-03 07:41:15 作者:乱了冬季末了绿ヽ

如果我重写System.Web.UI.Page构造,如图所示,什么时候DoSomething的()被调用的页面生命周期的角度?我似乎无法找到这个文件的任何地方。

If I override the System.Web.UI.Page constructor, as shown, when does DoSomething() get called in terms of the page lifecycle? I can't seem to find this documented anywhere.

namespace NameSpace1
{
    public partial class MyClass : System.Web.UI.Page
    {
        public MyClass()
        {
            DoSomething();
        }

        protected void Page_Load(object sender, EventArgs e)
        {

        }
    }
}

有关引用,这里是ASP.NET页面生命周期概述:

For reference, here is the ASP.NET Page Lifecycle Overview:

http://msdn.microsoft.com/en-us/library/ ms178472.aspx

原来最好的答案是正确的MSDN文章。我不得不仔细看一下图。构造是在页面生命周期中的第一个事件(涉及preINIT,初始化,加载等前)。

Turns out the best answer was right in the MSDN article. I just had to look carefully at the diagram. Construct is the very first event in the Page life cycle (comes before PreInit, Init, Load, etc).

推荐答案

DoSomething的();前成员方法将被调用。这不是关于页面的生命周期其实。这是关于类和实例。 ASP.NET创建MyClass的实例。 (构造器被执行)。之后,任何其他成员方法可以被调用。

DoSomething(); will be called before member methods. That's not about Page Lifecycle actually. It's about classes and instances. ASP.NET creates an instance of MyClass. (Contructor is executed). After that any other member methods can be called.