ASP Image causes page to load twice

D

DBLWizard

Howdy All,

I need some help I can't believe this is bug in Visual Studio 2005 and
hasn't been reported yet, but I have recreated it on two different
machines with the same result. I created a brand new website using VS
2005 and the default.aspx page looks like this:

<%@ Page Language="C#" AutoEventWireup="true"
CodeBehind="WebForm1.aspx.cs" Inherits="Pgi.Hub.WebForm1" %>

<!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:Image ID="imgTest" runat="server" />
<asp:Label ID="Label1" runat="server" Text="PageCount:"/>
<asp:Label ID="Label2" runat="server" />
</div>
</form>
</body>
</html>

And the Default.aspx.cs page looks like this:

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

if (Session["Default"] == null)
{
Session["Default"] = 0;
}

Session["Default"] = (int)Session["Default"] + 1;
Label2.Text = Session["Default"].ToString();
}
}

The first time the page loads it displays PageCount:1 if you hit
refresh again it shows PageCount:3. If you put a break point in the
Page_Load it will hit the break point twice each time you load the
page. This seems to be tied to the Image control, because you can
remove the <ASP:Image ...> entry from the page and it only loads
once. Also it seems to be a ghost page because the the second time
through the Label2.Text is set to 2 but the page that displays only
says 1.

I would appreciate any feedback or thoughts on what I'm doing wrong or
if there is some way around this and the best way to report it to
Microsoft if I'm not wrong.

Thanks

dbl
 
G

George Ter-Saakov

Your code works fine on my machine. IE 7.
What browser are you using?
I suspect the problem is that you have Image control and no source fro image
(src) assigned.
So the generated HTML <img src=""> might trigger the request for the same
page.
Since browser trying to concatenate the src path with the path of the page
and I am not sure what is the rule when src is blank.

George.



DBLWizard said:
Howdy All,

I need some help I can't believe this is bug in Visual Studio 2005 and
hasn't been reported yet, but I have recreated it on two different
machines with the same result. I created a brand new website using VS
2005 and the default.aspx page looks like this:

<%@ Page Language="C#" AutoEventWireup="true"
CodeBehind="WebForm1.aspx.cs" Inherits="Pgi.Hub.WebForm1" %>

<!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:Image ID="imgTest" runat="server" />
<asp:Label ID="Label1" runat="server" Text="PageCount:"/>
<asp:Label ID="Label2" runat="server" />
</div>
</form>
</html>

And the Default.aspx.cs page looks like this:

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

if (Session["Default"] == null)
{
Session["Default"] = 0;
}

Session["Default"] = (int)Session["Default"] + 1;
Label2.Text = Session["Default"].ToString();
}
}

The first time the page loads it displays PageCount:1 if you hit
refresh again it shows PageCount:3. If you put a break point in the
Page_Load it will hit the break point twice each time you load the
page. This seems to be tied to the Image control, because you can
remove the <ASP:Image ...> entry from the page and it only loads
once. Also it seems to be a ghost page because the the second time
through the Label2.Text is set to 2 but the page that displays only
says 1.

I would appreciate any feedback or thoughts on what I'm doing wrong or
if there is some way around this and the best way to report it to
Microsoft if I'm not wrong.

Thanks

dbl
 
L

Lit

Your code works fine on my machine.
when I refresh the count goes, 1, 2, 3.....
No loading twice.

create a new page and see may be you have some double subscription to your
events.
what happens if AutoEventWireup="true" is false?

Lit
 
D

DBLWizard

I question if "my" code works fine on your system. If you are saying
that you added a ImageUrl property to the Image and then the problem
went away then I can buy that. But I don't think my code as I entered
it above works perfectly on your system unless its something that
Microsoft did differently in IE 7. I am running both IE 6 and Firefox
2.0.0.6 and they both exhibit the behavior.

I just added the ImageUrl property and an image and the problem went
away. It even goes away if you have something in the
ImageUrl(ImageUrl="abcdefg") but it doesn't resolve properly. But if
the is blank ImageUrl="" or the tag is not there the problem does
exist.

I also reduced my page down to:

<%@ 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>
<img id="Image2" src="" alt=""/>
</div>
</form>
</body>
</html>

And it double loads so its not a Visual Studio bug but it is a bizarre
behavior. So thanks for pointing me in the correct direction.

dbl

Your code works fine on my machine. IE 7.
What browser are you using?
I suspect the problem is that you have Image control and no source fro image
(src) assigned.
So the generated HTML <img src=""> might trigger the request for the same
page.
Since browser trying to concatenate the src path with the path of the page
and I am not sure what is the rule when src is blank.

George.


Howdy All,
I need some help I can't believe this is bug in Visual Studio 2005 and
hasn't been reported yet, but I have recreated it on two different
machines with the same result. I created a brand new website using VS
2005 and the default.aspx page looks like this:
<%@ Page Language="C#" AutoEventWireup="true"
CodeBehind="WebForm1.aspx.cs" Inherits="Pgi.Hub.WebForm1" %>
<!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:Image ID="imgTest" runat="server" />
<asp:Label ID="Label1" runat="server" Text="PageCount:"/>
<asp:Label ID="Label2" runat="server" />
</div>
</form>
</html>
And the Default.aspx.cs page looks like this:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Session["Default"] == null)
{
Session["Default"] = 0;
}
Session["Default"] = (int)Session["Default"] + 1;
Label2.Text = Session["Default"].ToString();
}
}
The first time the page loads it displays PageCount:1 if you hit
refresh again it shows PageCount:3. If you put a break point in the
Page_Load it will hit the break point twice each time you load the
page. This seems to be tied to the Image control, because you can
remove the <ASP:Image ...> entry from the page and it only loads
once. Also it seems to be a ghost page because the the second time
through the Label2.Text is set to 2 but the page that displays only
says 1.
I would appreciate any feedback or thoughts on what I'm doing wrong or
if there is some way around this and the best way to report it to
Microsoft if I'm not wrong.

dbl
 
G

George Ter-Saakov

Well, you got your answer. It's a browser problem
Browser IE 6 and Firefox does not know what to do with html like
<img src="">
they are "concatenating" empty string with the page's url and comes up with
the same URL. And sends "GET" request for that image.

But I am surprised in that behavior as well.

George.



DBLWizard said:
I question if "my" code works fine on your system. If you are saying
that you added a ImageUrl property to the Image and then the problem
went away then I can buy that. But I don't think my code as I entered
it above works perfectly on your system unless its something that
Microsoft did differently in IE 7. I am running both IE 6 and Firefox
2.0.0.6 and they both exhibit the behavior.

I just added the ImageUrl property and an image and the problem went
away. It even goes away if you have something in the
ImageUrl(ImageUrl="abcdefg") but it doesn't resolve properly. But if
the is blank ImageUrl="" or the tag is not there the problem does
exist.

I also reduced my page down to:

<%@ 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>
<img id="Image2" src="" alt=""/>
</div>
</form>
</body>
</html>

And it double loads so its not a Visual Studio bug but it is a bizarre
behavior. So thanks for pointing me in the correct direction.

dbl

Your code works fine on my machine. IE 7.
What browser are you using?
I suspect the problem is that you have Image control and no source fro
image
(src) assigned.
So the generated HTML <img src=""> might trigger the request for the same
page.
Since browser trying to concatenate the src path with the path of the
page
and I am not sure what is the rule when src is blank.

George.


Howdy All,
I need some help I can't believe this is bug in Visual Studio 2005 and
hasn't been reported yet, but I have recreated it on two different
machines with the same result. I created a brand new website using VS
2005 and the default.aspx page looks like this:
<%@ Page Language="C#" AutoEventWireup="true"
CodeBehind="WebForm1.aspx.cs" Inherits="Pgi.Hub.WebForm1" %>
<!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:Image ID="imgTest" runat="server" />
<asp:Label ID="Label1" runat="server" Text="PageCount:"/>
<asp:Label ID="Label2" runat="server" />
</div>
</form>
</html>
And the Default.aspx.cs page looks like this:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Session["Default"] == null)
{
Session["Default"] = 0;
}
Session["Default"] = (int)Session["Default"] + 1;
Label2.Text = Session["Default"].ToString();
}
}
The first time the page loads it displays PageCount:1 if you hit
refresh again it shows PageCount:3. If you put a break point in the
Page_Load it will hit the break point twice each time you load the
page. This seems to be tied to the Image control, because you can
remove the <ASP:Image ...> entry from the page and it only loads
once. Also it seems to be a ghost page because the the second time
through the Label2.Text is set to 2 but the page that displays only
says 1.
I would appreciate any feedback or thoughts on what I'm doing wrong or
if there is some way around this and the best way to report it to
Microsoft if I'm not wrong.

dbl
 
D

DBLWizard

For everybody that this works fine with are ya'll using IE 7?

And I have decided that it still is a Visual Studio bug becuase if I
turn AutoEventsWireup to false the problem doesn't happen. Yes I know
that none of the events fire but still it is a bug in the event
handlers somewhere in Visual Studio. I don't have time at the moment
to dig into that and see exactly where the problem is as I have
already wasted a day trying to figure out what was causing this in the
first place ... but when I do I will try and add more details to this
post.

Thanks

dbl
 
L

Lit

I have IE 7 here. thanks for testing AutoEventsWireup.

Lit


DBLWizard said:
For everybody that this works fine with are ya'll using IE 7?

And I have decided that it still is a Visual Studio bug becuase if I
turn AutoEventsWireup to false the problem doesn't happen. Yes I know
that none of the events fire but still it is a bug in the event
handlers somewhere in Visual Studio. I don't have time at the moment
to dig into that and see exactly where the problem is as I have
already wasted a day trying to figure out what was causing this in the
first place ... but when I do I will try and add more details to this
post.

Thanks

dbl
 
G

George Ter-Saakov

I failed to understand reasoning why it's Visual Studio bug.....

If the AutoEventsWireup is false then Page_Load is not wired as an even
handler. Your page is still called twice.
Replace
protected void Page_Load(object sender, EventArgs e)

with

protected override void OnLoad(EventArgs e)

and you will see that. Even with AutoEventsWireup = false.

------------------------------

You just learned today (and we did too)

that having <img src=""> on a page.aspx is the same as having <img
src="page.aspx">

That is all.

I would call it a browser's bug at most. But even that would be a stretch,
cause I am positive that behavior when src is empty is not determined in the
standard (never read it :). But it's first time i come accross when someone
has empty src for image. If you need to make an invisible image just put
transparent gif 1x1 in there.



George.



DBLWizard said:
For everybody that this works fine with are ya'll using IE 7?

And I have decided that it still is a Visual Studio bug becuase if I
turn AutoEventsWireup to false the problem doesn't happen. Yes I know
that none of the events fire but still it is a bug in the event
handlers somewhere in Visual Studio. I don't have time at the moment
to dig into that and see exactly where the problem is as I have
already wasted a day trying to figure out what was causing this in the
first place ... but when I do I will try and add more details to this
post.

Thanks

dbl
 
S

shailesh patel

I am aware of following two things.

If you have img control with empty string assigned to src attribute.
<img src=??/>
<asp:image runat=?server? id=?img?/>
You may be forgot to assign imageurl or wanted to assign imageurl in code behind based on the some condition and that condition never gets executed and ended up being empty string assigned to src attribute when ASP.Net renders the page.

If you have empty string assigned to href attribute to html link for stylsheet.
<link rel=?stylesheet? href=??/>

If you have empty src attribute set to script.
<script src=?? type=?text/javascript?>

for more information refer this article.
http://patelshailesh.com/index.php/page_load-event-fires-twice-with-firefox-only



George Ter-Saakov wrote:

I failed to understand reasoning why it's Visual Studio bug.....
06-Sep-07

I failed to understand reasoning why it's Visual Studio bug....

If the AutoEventsWireup is false then Page_Load is not wired as an even
handler. Your page is still called twice
Replac
protected void Page_Load(object sender, EventArgs e

wit

protected override void OnLoad(EventArgs e

and you will see that. Even with AutoEventsWireup = false

-----------------------------

You just learned today (and we did too

that having <img src=""> on a page.aspx is the same as having <img
src="page.aspx"

That is all

I would call it a browser's bug at most. But even that would be a stretch,
cause I am positive that behavior when src is empty is not determined in the
standard (never read it :). But it's first time i come accross when someone
has empty src for image. If you need to make an invisible image just put
transparent gif 1x1 in there


George



Previous Posts In This Thread:

ASP Image causes page to load twice
Howdy All

I need some help I can't believe this is bug in Visual Studio 2005 an
hasn't been reported yet, but I have recreated it on two differen
machines with the same result. I created a brand new website using V
2005 and the default.aspx page looks like this

<%@ Page Language="C#" AutoEventWireup="true
CodeBehind="WebForm1.aspx.cs" Inherits="Pgi.Hub.WebForm1" %

<!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:Image ID="imgTest" runat="server" /
<asp:Label ID="Label1" runat="server" Text="PageCount:"/
<asp:Label ID="Label2" runat="server" /
</div
</form
</body
</html

And the Default.aspx.cs page looks like this

using System
using System.Data
using System.Configuration
using System.Web
using System.Web.Security
using System.Web.UI
using System.Web.UI.WebControls
using System.Web.UI.WebControls.WebParts
using System.Web.UI.HtmlControls

public partial class _Default : System.Web.UI.Pag

protected void Page_Load(object sender, EventArgs e


if (Session["Default"] == null

Session["Default"] = 0


Session["Default"] = (int)Session["Default"] + 1
Label2.Text = Session["Default"].ToString()



The first time the page loads it displays PageCount:1 if you hi
refresh again it shows PageCount:3. If you put a break point in th
Page_Load it will hit the break point twice each time you load th
page. This seems to be tied to the Image control, because you ca
remove the <ASP:Image ...> entry from the page and it only load
once. Also it seems to be a ghost page because the the second tim
through the Label2.Text is set to 2 but the page that displays onl
says 1

I would appreciate any feedback or thoughts on what I'm doing wrong o
if there is some way around this and the best way to report it t
Microsoft if I'm not wrong

Thank

dbl

Your code works fine on my machine. IE 7.What browser are you using?
Your code works fine on my machine. IE 7.
What browser are you using?
I suspect the problem is that you have Image control and no source fro image
(src) assigned.
So the generated HTML <img src=""> might trigger the request for the same
page.
Since browser trying to concatenate the src path with the path of the page
and I am not sure what is the rule when src is blank.

George.




Your code works fine on my machine.when I refresh the count goes, 1, 2, 3.....
Your code works fine on my machine.
when I refresh the count goes, 1, 2, 3.....
No loading twice.

create a new page and see may be you have some double subscription to your
events.
what happens if AutoEventWireup="true" is false?

Lit



I question if "my" code works fine on your system.
I question if "my" code works fine on your system. If you are saying
that you added a ImageUrl property to the Image and then the problem
went away then I can buy that. But I don't think my code as I entered
it above works perfectly on your system unless its something that
Microsoft did differently in IE 7. I am running both IE 6 and Firefox
2.0.0.6 and they both exhibit the behavior.

I just added the ImageUrl property and an image and the problem went
away. It even goes away if you have something in the
ImageUrl(ImageUrl="abcdefg") but it doesn't resolve properly. But if
the is blank ImageUrl="" or the tag is not there the problem does
exist.

I also reduced my page down to:

<%@ 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>
<img id="Image2" src="" alt=""/>
</div>
</form>
</body>
</html>

And it double loads so its not a Visual Studio bug but it is a bizarre
behavior. So thanks for pointing me in the correct direction.

dbl


Re: ASP Image causes page to load twice
And on mine.


Same here.


--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Well, you got your answer.
Well, you got your answer. It's a browser problem
Browser IE 6 and Firefox does not know what to do with html like
<img src="">
they are "concatenating" empty string with the page's url and comes up with
the same URL. And sends "GET" request for that image.

But I am surprised in that behavior as well.

George.




For everybody that this works fine with are ya'll using IE 7?
For everybody that this works fine with are ya'll using IE 7?

And I have decided that it still is a Visual Studio bug becuase if I
turn AutoEventsWireup to false the problem doesn't happen. Yes I know
that none of the events fire but still it is a bug in the event
handlers somewhere in Visual Studio. I don't have time at the moment
to dig into that and see exactly where the problem is as I have
already wasted a day trying to figure out what was causing this in the
first place ... but when I do I will try and add more details to this
post.

Thanks

dbl


I have IE 7 here. thanks for testing AutoEventsWireup.
I have IE 7 here. thanks for testing AutoEventsWireup.

Lit

I failed to understand reasoning why it's Visual Studio bug.....
I failed to understand reasoning why it's Visual Studio bug.....

If the AutoEventsWireup is false then Page_Load is not wired as an even
handler. Your page is still called twice.
Replace
protected void Page_Load(object sender, EventArgs e)

with

protected override void OnLoad(EventArgs e)

and you will see that. Even with AutoEventsWireup = false.

------------------------------

You just learned today (and we did too)

that having <img src=""> on a page.aspx is the same as having <img
src="page.aspx">

That is all.

I would call it a browser's bug at most. But even that would be a stretch,
cause I am positive that behavior when src is empty is not determined in the
standard (never read it :). But it's first time i come accross when someone
has empty src for image. If you need to make an invisible image just put
transparent gif 1x1 in there.



George.





Submitted via EggHeadCafe - Software Developer Portal of Choice
BizTalk Configure and Send SMTP Mail Based on Message Within an Orchestration
http://www.eggheadcafe.com/tutorial...1-a2f309a021c2/biztalk-configure-and-sen.aspx
 

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

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top