Page_Load in C#

Sudha picture Sudha · Apr 30, 2013 · Viewed 40.8k times · Source

I am working with C# web application. I want to know deeply about the page events. Because I thought that the page load event happens first (when a page is requested in browser). But when I tried with commenting the method protected void Page_Load(object sender, EventArgs e) the page get loaded without error.

Answer

Newton Sheikh picture Newton Sheikh · Apr 30, 2013

off-course your webpage will work even if there is no Page_Load() method. Before a Page_Load() events like PreInit, Init() etc are called. Refer to page life cycle.

Page_Load() method is called after a preLoad event. With Page_Load() you can set default values or check for postBacks etc.

 protected void Page_Load(object sender, EventArgs e)
    {
        int x = 10;
    }

write this and put a break-point on int x = 10; watch sender and e.