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 http://img156.imageshack.us/img156/9246/lifecyclen.jpg
If you use code-behind class files with . aspx pages, you can separate the presentation code from the core application logic (or code-behind). The code-behind class file is compiled so that it can be created and used as an object. This allows access to its properties, its methods, and its event handlers.
What is advantage of code behind coding in ASP.NET? code-behind files allow for a cleaner system implementation. Code-behind files allow a developer to separate the UI display from the UI processing.
The code-behind feature of ASP.NET enables you to divide an ASP.NET page into two files - one consisting of the presentation data, and the second, which is also called the code-behind file, consisting of all the business logic.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With