By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,967 Members | 1,554 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,967 IT Pros & Developers. It's quick & easy.

Code in Page_Load executes twice

P: n/a
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
Share this Question
Share on Google+
4 Replies


P: n/a
David,
No its not a bug. What might be happening is that you've got
AutoEventiWireup="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

P: n/a
On Aug 8, 12:52 pm, Peter Bromberg [C# MVP]
<pbromb...@yahoo.yohohhoandabottleofrum.comwrote :
David,
No its not a bug. What might be happening is that you've got
AutoEventiWireup="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

P: n/a
for example:
Page directive:
<%@ PageAutoEventWireup="true" ...
and in Page_Init:
this.Load += new EventHandler(Page_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...@yahoo.yohohhoandabottleofrum.comwrote :
David,
No its not a bug. What might be happening is that you've got
AutoEventiWireup="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

P: n/a
>>>>>>>this.Load += new EventHandler(Page_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
<SergeyPoberezovs...@discussions.microsoft.comwrot e:
for example:
Page directive:
<%@ PageAutoEventWireup="true" ...
and in Page_Init:
this.Load += new EventHandler(Page_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...@yahoo.yohohhoandabottleofrum.comwrote :
David,
No its not a bug. What might be happening is that you've got
AutoEventiWireup="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 discussion thread is closed

Replies have been disabled for this discussion.