user3308043
user3308043

Reputation: 827

ASP.net Page_Load method logic

I'm looking to gain an overall, high-level understand of what exactly happens when you put logic in the Page_Load method from an OOP viewpoint.

Code as follows:

public partial class _Default : System.Web.UI.Page
{

    protected void Page_Load(object sender, EventArgs e)
    {
         Label1.Text = "Hello";
    }
}

I think I have a solid understanding, but would love for somebody to confirm my observations and point out any errors or false assumptions that I'm making.

So from what I understand,

Other than these observations, I have a question or two:

Is there no other implementation for Page_Load anywhere?

What is the OOP logic behind Page_Load being protected?

What initiates Page_Load?

Upvotes: 0

Views: 279

Answers (2)

wazz
wazz

Reputation: 5058

notice that the partial class inherits from System.Web.UI.Page. some good info to dig into there.

Upvotes: 1

Ben N
Ben N

Reputation: 2923

Page_Load could be called anything, it's just being subscribed to the Load event of the Control class. It's usually defined only once, but if you wanted to you could put some more handlers onto it, just like with any event.

Similarly, the protected status of Page_Load doesn't mean a lot. It could really be defined anywhere; it could be private or public. It's an event handler and is therefore wired up to the invocation list for an event.

And for your third question, which you probably answered yourself by now, it's an event. Invocation of every subscribed handler happens when the server fires the Load event, when a user requests the page.

Upvotes: 1

Related Questions