473,395 Members | 1,464 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Page Load Event Fires Twice

I am having a problem that the page load event fires twice in reponse to an
autopostback. The first time, the IsPostBack property is true, and the
second time it it false. This is causing many uneeded database calls, since
many of them do not need to be fired on a PostBack.

I have already set the AutoEventWireup=false in the ASPX @Page directive. I
am setting the visible property of a datagrid in some of my methods, but I
commented out that line completely and I still have the problem.

Any help is appreciated.

Thanks,
Asa Monsey
Nov 18 '05 #1
5 7490
This often happens when you have a handler registered more then once.

See if you have the event registered in both the HTML and C# code.

"Asa Monsey" <As*@NoMoreViri.com> wrote in message
news:91**********************************@microsof t.com...
I am having a problem that the page load event fires twice in reponse to an autopostback. The first time, the IsPostBack property is true, and the
second time it it false. This is causing many uneeded database calls, since many of them do not need to be fired on a PostBack.

I have already set the AutoEventWireup=false in the ASPX @Page directive. I am setting the visible property of a datagrid in some of my methods, but I
commented out that line completely and I still have the problem.

Any help is appreciated.

Thanks,
Asa Monsey

Nov 18 '05 #2
Hi Asa,

From the description, one of your asp.net's Page_load is entered twice and
the first time the
"IsPostBack" property is true and the next time, it is "false" ,yes?

As for the first "enter"(IsPostBack == true), I'm also abit confused. Is
there any particular code in the codebehind or any html element in the aspx
page template which may cause the page be self requested? Also, to
throubleshoot, you can build a simple page which can repro the problem and
analyize the page's html source step by step
In addition, you can also provide the problem page's code here so that we
can do some tests locally. Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx

Nov 18 '05 #3
Hi,

Thanks for the followup and the code snippet you provided. I copy the page
code into one of my web project and in my test, the page only load once.
How do you found that it is loaded twice? Via set break point and F5
debugging or put some code in the Page_Load event?
I think you can put some code such as
Response.Write (..) to write some statements to see whether it is always
output twice (both initial request and postback)

Also, I suggest that you create another new web application and put the
simple page in it to see whether the problem reoccur. Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx

Nov 18 '05 #4
Hi Asa,

Thanks for your followup. I think you've excatly found the cause and after
some futher test, here are my understanding on the reason of this behavior:

1. First the <body> 's "background" attribute should be set with a url
value since its for settintg the page's background image rather than
background color :)

2. Then, when you set the "background" as a web color value such as
#XXXXXX, the web browser will treat the "#XXXXXX" as a url. As we know, the
#XXXXXX is are particular link type( anchor) which point to the self page's
certain portion. That makes the browser send another get request when
parsing to the <body background="#xxxxxx" > line.
Also, you can make a same test via the following page code:

<body>
<img src="#" />
.....
</body>

This will also cause the self page be requested twice. But this only occurs
when the page is posted back rather than the inital request, the reason is
in 3.

3. The IE browser will treat the GET and POST request to a single url as
different request. When the page is first time requested( not post back),
it send a get request, and the page return, and when parsing to the <body
background="#xxxxxx" >, it won't send a new GET request because it has done
it already.
However, when post back, since post back reqeust is a POST request, IE
browser think it is different from the GET request, so he will send another
GET request when dealing with the <body background="#xxxxxx">

Anyway, I'm glad that we finally figure out the problem. And it maybe a
good instruction when next time we meet such problem. :)

Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx

Nov 18 '05 #5
Steven,

Thank you for your thorough explanation of the causes of this behavior. It
makes perfect sense now. I don't know why the color reference was in that
attribute, since I have inherited this code from previous developers.

This should significantly improve our database load, since there will be
many fewer calls now.

Thanks again,
Asa Monsey

"Steven Cheng[MSFT]" wrote:
Hi Asa,

Thanks for your followup. I think you've excatly found the cause and after
some futher test, here are my understanding on the reason of this behavior:

1. First the <body> 's "background" attribute should be set with a url
value since its for settintg the page's background image rather than
background color :)

2. Then, when you set the "background" as a web color value such as
#XXXXXX, the web browser will treat the "#XXXXXX" as a url. As we know, the
#XXXXXX is are particular link type( anchor) which point to the self page's
certain portion. That makes the browser send another get request when
parsing to the <body background="#xxxxxx" > line.
Also, you can make a same test via the following page code:

<body>
<img src="#" />
.....
</body>

This will also cause the self page be requested twice. But this only occurs
when the page is posted back rather than the inital request, the reason is
in 3.

3. The IE browser will treat the GET and POST request to a single url as
different request. When the page is first time requested( not post back),
it send a get request, and the page return, and when parsing to the <body
background="#xxxxxx" >, it won't send a new GET request because it has done
it already.
However, when post back, since post back reqeust is a POST request, IE
browser think it is different from the GET request, so he will send another
GET request when dealing with the <body background="#xxxxxx">

Anyway, I'm glad that we finally figure out the problem. And it maybe a
good instruction when next time we meet such problem. :)

Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx


Nov 18 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Colin Basterfield | last post by:
Hi, Hmmm, a strange one for me, but hopefully not for others... I have a base page which has virtual protected void PageLoadEvent(object sender, System.EventArgs e){} In the Page_Load...
2
by: John Lau | last post by:
Hi, Is there documentation that talks about the page lifecycle, the lifecycle of controls on the page, and the rendering of inline code, in a single document? Thanks, John
1
by: Magdelin | last post by:
Hi, I have a BasePage class from which all other ASPX pages of the project is inherited. The BasePage class implements Page_Load event handler. All child pages have its AutoEventWireUp property...
1
by: PCH | last post by:
Hello all, Been messing the the dec CTP of .net 2 Heres the situation: I have a master page with the contents control and a button control (call it btnRefresh). I have a child page that...
1
by: Bill Manring | last post by:
The startup page for my ASP.NET application is an HTML frames page with two frames. This seems to cause the Session_Start event in the Global.asax file to fire twice. When I change the startup...
8
by: MaryA | last post by:
I have an aspx page that loads twice inspite of using the IsPostBack i removed all controls from the page and still the page_load event is called twice I appriciate any help coz i have lost...
8
by: TS | last post by:
Hi, i have inherited a page from another user. The page is the target frame in a frameset. for some reason the whole page runs twice (page_load, init, etc. all run twice) I can't figure out how...
0
by: Managed Code | last post by:
Hello All, Here is my issue and thanks in advance for any assistance. I have a base page with a dropdownlist that fires an event with the selected index. The content page catches the event and...
0
by: manywolf | last post by:
I have an aspx page that fires the page load event twice for every load. I tried every fix that was suggested in all the posts on this and other forums. None changed the behavior. After one post that...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.