ASP.NET Page_Init fired twice!

I have AutoEventWireup = "true" and in my code

protected void Page_Init(object sender, EventArgs e) { } 

When I debug, the Page_Init method gets run twice!

What's happening?

+4
source share
3 answers

Let us make sure that we are based here:

Do you have any controls on your page with server events? If so, remember that each postback re-creates the entire page. Thus, to handle the event means that all the necessary codes put the page together, including the Init and Load events.

Always two, no more, no less. Request and response.

+7
source

You probably have some kind of redirect or ajax redirect that works.

+3
source

Do you have code somewhere that looks something like this?

 this.Init += Page_Init; 

If so, you accidentally trigger the event twice. Delete the wiring manually or set AutoEventWireup to false .

+2
source

All Articles