ASP.NET 2.0: Page loaded twice on debug.

G

Guest

Hi,

I recently converted an ASP.NET project for framework 2.0. I never had any
problem using VS 2003 but today, debugging a page, I get surprised when I saw
that once debugged the last line, it was automatically debugged another time
since the first line and even the "if (!IsPostBack)..." code was runned (when
it shouldn't, previously was not runned as it should be)... so many variables
are reinitializated and it doesn't runs as it should. Hope I have explained
the problem clearly... anyone has had this problem? Running the same page
with VS 2003 runs only once and fine.

Thanks in advance!!!
 
F

Frans Bouma [C# MVP]

Tomás Martínez said:
Hi,

I recently converted an ASP.NET project for framework 2.0. I never
had any problem using VS 2003 but today, debugging a page, I get
surprised when I saw that once debugged the last line, it was
automatically debugged another time since the first line and even the
"if (!IsPostBack)..." code was runned (when it shouldn't, previously
was not runned as it should be)... so many variables are
reinitializated and it doesn't runs as it should. Hope I have
explained the problem clearly... anyone has had this problem? Running
the same page with VS 2003 runs only once and fine.

This is an issue I ran into a couple of times myself as well, and it's
due to a change in ASP.NET: in ASP.NET 1.x, Autowire events was set to
false and teh Load event handler (Page_Load) was bound in a generated
method in the code behind file.

In ASP.NET 2.0, autowire events (in the PAGE directive in the aspx
html code) is set to true by default and this already binds the
page_load event handler routine to the Load event of the page
automatically. So if you migrate a page to ASP.NET 2.0, and you set
autowire events to true in the page tag in the html, AND you have the
page_load event handler bound by code in the code behind as well (check
the generated region in the code behind for this), you'll get a call to
the page_load routine TWICE as the routine is bound to the event twice
(once automatically and once through the .net 1.x code in the generated
region).

so simply remove handler setup in the generated code region and you're
set :).

FB

--
------------------------------------------------------------------------
Lead developer of LLBLGen Pro, the productive O/R mapper for .NET
LLBLGen Pro website: http://www.llblgen.com
My .NET blog: http://weblogs.asp.net/fbouma
Microsoft MVP (C#)
------------------------------------------------------------------------
 
G

Guest

Hi!

First of all, thanks for your reply!!! :) So... I understand you tell me to
remove this line

this.Load += new System.EventHandler(this.Page_Load);

in the InitializeComponent(), don't you? The problem is that I don't have
this, but maybe I didn't understand you. Thanks again and sorry about disturb.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top