Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET Page_Init Fired Twice!

Tags:

asp.net

I have AutoEventWireup="true" and in my code behind

protected void Page_Init(object sender, EventArgs e)
{


}

When I'm debugging, the Page_Init method is getting fired twice!

Whats going on?

like image 214
AJM Avatar asked Jul 16 '09 15:07

AJM


3 Answers

Let's make sure we cover the basics here:

Do you have any controls on your page that have server events? If so, remember that every postback re-creates the entire page. So, to handle an event means running all of the code required put the page together, including your Init and Load events.

Always two there are, no more no less. A request and a response.

like image 73
Joel Coehoorn Avatar answered Oct 08 '22 03:10

Joel Coehoorn


You probably have some sort of redirect or ajax postback that is firing.

like image 35
Chris Avatar answered Oct 08 '22 01:10

Chris


Do you have any code anywhere that looks something like this?

this.Init += Page_Init;

If so you are accidentally wiring the event twice. Either delete the manual event wiring or set AutoEventWireup to false.

like image 45
Andrew Hare Avatar answered Oct 08 '22 03:10

Andrew Hare