views:

99

answers:

2

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)
        {

        }
    }
}

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

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

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).

Diagram

+1  A: 

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.

hakan
A: 

To answer your question, an instance is created at step 10:

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

Scroll down to "The request is processed by the HttpApplication pipeline."

Raj Kaimal