ASP.Net - Page_Load and Page_Init called every time a button is clicked?

Thus, I have absolutely no logic in my code. I have two methods Page_Init and Page_Load

Both methods are called every time I click a button. It makes sense to call the page_load call. But why is the call to Page_Init called every time?

 protected void Page_Init(Object sender, EventArgs e) { } protected void Page_Load(object sender, EventArgs e) { } protected void Button1_Click1(object sender, EventArgs e) { // Do something here } 
+4
source share
1 answer

I think you are not aware of the page life cycle.

Page_Init will always be called when the page is created and called before the page loads.

Pre Init is called, then Init is called, then Pre Load, and then Load, then Pre Render, and then Render, almost every time the postback occurs.

You can do this trick if you are not on a live server. Add

 Trace ="true" 

in the page directive, which will show you the full page loop.

Like this,

  <%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" Trace="true"%> 
+8
source

All Articles