|
|
|
start date: Wed, 08 Aug 2007 10:54:10 -0000,
posted on: microsoft.public.dotnet.framework.aspnet
back
| Thread Index |
|
1
David C
|
|
2
Peter Bromberg [C# MVP]
|
|
3
Sergey Poberezovskiy
|
|
4
Joey
|
|
5
David C
|
|
6
Joey
|
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.
Date:Wed, 08 Aug 2007 10:54:10 -0000
Author:
|
RE: Code in Page_Load executes twice
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.
>
>
Date:Wed, 8 Aug 2007 10:52:05 -0700
Author:
|
Re: Code in Page_Load executes twice
On Aug 8, 12:52 pm, Peter Bromberg [C# MVP]
wrote:
> 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.
Date:Wed, 08 Aug 2007 11:29:45 -0700
Author:
|
Re: Code in Page_Load executes twice
On Aug 8, 10:52 am, Peter Bromberg [C# MVP]
wrote:
> 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, it is eminently reproducible. Have you tried it? Start a new
website, on Default.aspx, throw in an image button control without
setting ImageUrl and put your break point in Page_Load. If it does
not, I would like to know.
And then put something for ImageUrl. It does not have to be a
existent file. Put anything and then run it. It does not execute
Page_Load twice.
This is what my aspx page looks which executes Page_Load twice.
<%@ Page Language="C#" AutoEventWireup="true"
CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ImageButton ID="ImageButton1" runat="server"
ImageUrl="blah.jpg"/>
</div>
</form>
</body>
</html>
Date:Wed, 08 Aug 2007 15:17:28 -0700
Author:
|
Re: Code in Page_Load executes twice
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]
> wrote:
> > 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.
>
>
Date:Wed, 8 Aug 2007 19:34:00 -0700
Author:
|
Re: Code in Page_Load executes twice
>>>>>>>> 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
wrote:
> 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]
> > wrote:
> > > 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 -
Date:Thu, 09 Aug 2007 07:17:58 -0700
Author:
|
|
|