473,713 Members | 2,598 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Code in Page_Load executes twice

I spent the last four hours trying to figure out why Page_Load would
execute twice. Even stranger was that everything within if (!
IsPostBack){... .} executed twice as well. There is no rhyme or reason
for that.

Here is what I found out.

When you have an ImageButton with no ImageURL set, it will always do
that. This was not the case with .NET 1.0. So if you need to
experiment with ImageButton, set something to the ImageUrl
attribute.

This has to be a bug, but who knows.

3:55 AM. Good night and Death to Microsoft.

Aug 8 '07 #1
4 2858
David,
No its not a bug. What might be happening is that you've got
AutoEventiWireu p="true" in your <%@ Page directive, PLUS you may also have
duplicate event delegate wireups in your codebehind. One or the other needs
to go.
There may be other causes to this problem also, but usually that's the main
one.
-- Peter
Recursion: see Recursion
site: http://www.eggheadcafe.com
unBlog: http://petesbloggerama.blogspot.com
bogMetaFinder: http://www.blogmetafinder.com

"David C" wrote:
I spent the last four hours trying to figure out why Page_Load would
execute twice. Even stranger was that everything within if (!
IsPostBack){... .} executed twice as well. There is no rhyme or reason
for that.

Here is what I found out.

When you have an ImageButton with no ImageURL set, it will always do
that. This was not the case with .NET 1.0. So if you need to
experiment with ImageButton, set something to the ImageUrl
attribute.

This has to be a bug, but who knows.

3:55 AM. Good night and Death to Microsoft.

Aug 8 '07 #2
On Aug 8, 12:52 pm, Peter Bromberg [C# MVP]
<pbromb...@yaho o.yohohhoandabo ttleofrum.comwr ote:
David,
No its not a bug. What might be happening is that you've got
AutoEventiWireu p="true" in your <%@ Page directive, PLUS you may also have
duplicate event delegate wireups in your codebehind. One or the other needs
to go.
There may be other causes to this problem also, but usually that's the main
one.
-- Peter
Recursion: see Recursion
site: http://www.eggheadcafe.com
unBlog: http://petesbloggerama.blogspot.com
bogMetaFinder: http://www.blogmetafinder.com

"David C" wrote:
I spent the last four hours trying to figure out why Page_Load would
execute twice. Even stranger was that everything within if (!
IsPostBack){... .} executed twice as well. There is no rhyme or reason
for that.
Here is what I found out.
When you have an ImageButton with no ImageURL set, it will always do
that. This was not the case with .NET 1.0. So if you need to
experiment with ImageButton, set something to the ImageUrl
attribute.
This has to be a bug, but who knows.
3:55 AM. Good night and Death to Microsoft.- Hide quoted text -

- Show quoted text -
>>>>>>>>PLUS you may also have
duplicate event delegate wireups in your codebehind.

what do you mean by this? can you give an example?

We have always had problems with Page_Load and !IsPostBack firing
multiple times. I would LOVE to fix this.

Aug 8 '07 #3
for example:
Page directive:
<%@ PageAutoEventWi reup="true" ...
and in Page_Init:
this.Load += new EventHandler(Pa ge_Load);

I think the default for the page is true, unless you specifically override
this either in web.config or on the page level

"Joey" wrote:
On Aug 8, 12:52 pm, Peter Bromberg [C# MVP]
<pbromb...@yaho o.yohohhoandabo ttleofrum.comwr ote:
David,
No its not a bug. What might be happening is that you've got
AutoEventiWireu p="true" in your <%@ Page directive, PLUS you may also have
duplicate event delegate wireups in your codebehind. One or the other needs
to go.
There may be other causes to this problem also, but usually that's the main
one.
-- Peter
Recursion: see Recursion
site: http://www.eggheadcafe.com
unBlog: http://petesbloggerama.blogspot.com
bogMetaFinder: http://www.blogmetafinder.com

"David C" wrote:
I spent the last four hours trying to figure out why Page_Load would
execute twice. Even stranger was that everything within if (!
IsPostBack){... .} executed twice as well. There is no rhyme or reason
for that.
Here is what I found out.
When you have an ImageButton with no ImageURL set, it will always do
that. This was not the case with .NET 1.0. So if you need to
experiment with ImageButton, set something to the ImageUrl
attribute.
This has to be a bug, but who knows.
3:55 AM. Good night and Death to Microsoft.- Hide quoted text -
- Show quoted text -
>>>>>>>PLUS you may also have
duplicate event delegate wireups in your codebehind.

what do you mean by this? can you give an example?

We have always had problems with Page_Load and !IsPostBack firing
multiple times. I would LOVE to fix this.

Aug 9 '07 #4
>>>>>>>this.Loa d += new EventHandler(Pa ge_Load);

I don't have any lines of code that do this. I always select the
control in the properties editor in the IDE, click the show events
button (lightning bolt) and then double click in the appropriate
field. An example would be RowDataBound for a gridview. Then I am
taken back to my code behind page to a stubbed out code block. At this
point I know the wireup for the event has been created...it's just not
in MY code.

Now, we have LOTS of pages that execute Page_Load and !IsPostBack code
blocks two, three, four or more times. In some situations this creates
serious problems, such as database inserts occurring twice, etc...This
has been a thorn in my side for a long time, and I would really like
to figure out what is causing it.

Oh yeah, we have lots of imagebuttons without imageurl properties set
to anything. They are skinned instead.

We have also noticed this to be much more of a problem when using
Firefox.

On Aug 8, 9:34 pm, Sergey Poberezovskiy
<SergeyPoberezo vs...@discussio ns.microsoft.co mwrote:
for example:
Page directive:
<%@ PageAutoEventWi reup="true" ...
and in Page_Init:
this.Load += new EventHandler(Pa ge_Load);

I think the default for the page is true, unless you specifically override
this either in web.config or on the page level

"Joey" wrote:
On Aug 8, 12:52 pm, Peter Bromberg [C# MVP]
<pbromb...@yaho o.yohohhoandabo ttleofrum.comwr ote:
David,
No its not a bug. What might be happening is that you've got
AutoEventiWireu p="true" in your <%@ Page directive, PLUS you may also have
duplicate event delegate wireups in your codebehind. One or the other needs
to go.
There may be other causes to this problem also, but usually that's the main
one.
-- Peter
Recursion: see Recursion
site: http://www.eggheadcafe.com
unBlog: http://petesbloggerama.blogspot.com
bogMetaFinder: http://www.blogmetafinder.com
"David C" wrote:
I spent the last four hours trying to figure out why Page_Load would
execute twice. Even stranger was that everything within if (!
IsPostBack){... .} executed twice as well. There is no rhyme or reason
for that.
Here is what I found out.
When you have an ImageButton with no ImageURL set, it will always do
that. This was not the case with .NET 1.0. So if you need to
experiment with ImageButton, set something to the ImageUrl
attribute.
This has to be a bug, but who knows.
3:55 AM. Good night and Death to Microsoft.- Hide quoted text -
- Show quoted text -
>>>>>>>>PLUS you may also have
duplicate event delegate wireups in your codebehind.
what do you mean by this? can you give an example?
We have always had problems with Page_Load and !IsPostBack firing
multiple times. I would LOVE to fix this.- Hide quoted text -

- Show quoted text -

Aug 9 '07 #5

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

Similar topics

8
9558
by: Andy | last post by:
Visual Studio 2003 web form problem using C#. My Page_Load or OnInit routines seems to be called twice for every post back to the server. I have 2 web forms that produce this behaviour, all of the others just run these routines once. Any ideas!
1
3386
by: bminder | last post by:
In the asp.net pages below, Common.vb has an overridable Page_Load sub. In the consuming page, Two.aspx, the Page_Load sub is inherited, but for some reason it (Overrides Sub Page_Load) executes twice. In another "regular" asp.net page that inherits only from its own codebehind page, the page load only executes once as you'd expect. Any ideas why the page_load fires twice in the former example? Thanks,
2
336
by: dx | last post by:
I have a simple user control (.ascx) that is dynamically instantiated in the calling aspx page and added to the control tree (within the page_load.) I have checked and the calling page only executes it's page_load once. Why is the page_load of the ascx fired twice? Thanks in advance, stan
4
2638
by: etropic | last post by:
Im confused I want an .aspx page to have a table with my data in it. At first I wrote FillTablew(); in my Page_Load even in the Code Behind file. I had it loop the db etc. and use Response.Write of a bunch of strings. This works great as long as all I want is the results of those Response.Writes I believe what I REALLY want is to convert those Response.Writes to a str cat in the code behind, and then in the body of my .aspx page to do...
3
2532
by: erdem | last post by:
hi, i have a problem with asp.net when i was debugging i put breakpoint to pageload event and then i discovered that page is loaded once (explorer shows full page correctly but continues loading) but then somehow page load executes again and then page is displayed... but there is different thing. when page executes page load second time,,
4
3182
by: Guadala Harry | last post by:
Just wondering what could cause this: I have observed that when first opening an aspx page, the Page_Load event fires as expected. Then I go to other pages in the site. When returning to any page that has been previously viewed, the Page_Load event does not fire (or at least the Page_Load event procedure is not executed). FWIW: PostBacks are working fine (meaning that the Page_Load event procedure executes on PostBacks). The problem is just...
2
3060
by: magister | last post by:
Does smartnavigation on parent page make user controls page_load twice... Any fixes for this!!! Problem is when boss sees smartnavigation he likes but it causes lots of other bugs....why why!!! Microsoft fix it!!!
6
5997
by: Dot net work | last post by:
I've read quite a few threads on these groups about this. When someone says the following: "My Page_Load gets called twice on a button click postback" The replies are: "Do you have AutoEventWireup=True in your page header?" In my project, I have this set to false - everywhere.
1
1570
by: Rippo | last post by:
Hi I have a Master page that opens up a db connection, performs a couple of global routines in the page_load event. All of my other web pages in my web app then inherits this Master Page I also have a page_load event on all of the other pages. I am finding however that the page_load event on the template page is being fired twice.
0
8794
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9300
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9166
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7939
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4459
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4713
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3154
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2509
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2101
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.