Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / September 2007

Tip: Looking for answers? Try searching our database.

ASP Image causes page to load twice

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
DBLWizard - 06 Sep 2007 17:53 GMT
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
George Ter-Saakov - 06 Sep 2007 18:45 GMT
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,
>
[quoted text clipped - 21 lines]
>    </div>
>    </form>

> </html>
>
[quoted text clipped - 41 lines]
>
> dbl
DBLWizard - 06 Sep 2007 19:21 GMT
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?
[quoted text clipped - 77 lines]
>
> > dbl
George Ter-Saakov - 06 Sep 2007 19:48 GMT
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.

>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
[quoted text clipped - 118 lines]
>>
>> > dbl
Lit - 06 Sep 2007 19:06 GMT
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

> Howdy All,
>
[quoted text clipped - 67 lines]
>
> dbl
Mark Rae [MVP] - 06 Sep 2007 19:37 GMT
> Your code works fine on my machine.

And on mine.

> when I refresh the count goes, 1, 2, 3.....
> No loading twice.

Same here.

Signature

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

DBLWizard - 06 Sep 2007 20:00 GMT
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

> > Your code works fine on my machine.
>
[quoted text clipped - 8 lines]
> Mark Rae
> ASP.NET MVPhttp://www.markrae.net
Lit - 06 Sep 2007 20:15 GMT
I have IE 7 here.   thanks for testing AutoEventsWireup.

Lit

> For everybody that this works fine with are ya'll using IE 7?
>
[quoted text clipped - 23 lines]
>> Mark Rae
>> ASP.NET MVPhttp://www.markrae.net
George Ter-Saakov - 06 Sep 2007 20:44 GMT
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.

> For everybody that this works fine with are ya'll using IE 7?
>
[quoted text clipped - 23 lines]
>> Mark Rae
>> ASP.NET MVPhttp://www.markrae.net

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.