ASP Image causes page to load twice

Discussion in 'ASP .Net' started by DBLWizard, Sep 6, 2007.

  1. DBLWizard

    DBLWizard Guest

    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
    DBLWizard, Sep 6, 2007
    #1
    1. Advertising

  2. 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" <> wrote in message
    news:...
    > 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
    >
    George Ter-Saakov, Sep 6, 2007
    #2
    1. Advertising

  3. DBLWizard

    Lit Guest

    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


    "DBLWizard" <> wrote in message
    news:...
    > 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
    >
    Lit, Sep 6, 2007
    #3
  4. DBLWizard

    DBLWizard Guest

    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

    On Sep 6, 11:45 am, "George Ter-Saakov" <> wrote:
    > 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" <> wrote in message
    >
    > news:...
    >
    > > 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
    DBLWizard, Sep 6, 2007
    #4
  5. "Lit" <> wrote in message
    news:%...

    > Your code works fine on my machine.


    And on mine.

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


    Same here.


    --
    Mark Rae
    ASP.NET MVP
    http://www.markrae.net
    Mark Rae [MVP], Sep 6, 2007
    #5
  6. 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" <> wrote in message
    news:...
    >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
    >
    > On Sep 6, 11:45 am, "George Ter-Saakov" <> wrote:
    >> 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" <> wrote in message
    >>
    >> news:...
    >>
    >> > 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

    >
    >
    George Ter-Saakov, Sep 6, 2007
    #6
  7. DBLWizard

    DBLWizard Guest

    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

    On Sep 6, 12:37 pm, "Mark Rae [MVP]" <> wrote:
    > "Lit" <> wrote in message
    >
    > news:%...
    >
    > > Your code works fine on my machine.

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

    >
    > Same here.
    >
    > --
    > Mark Rae
    > ASP.NET MVPhttp://www.markrae.net
    DBLWizard, Sep 6, 2007
    #7
  8. DBLWizard

    Lit Guest

    I have IE 7 here. thanks for testing AutoEventsWireup.

    Lit


    "DBLWizard" <> wrote in message
    news:...
    > 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
    >
    > On Sep 6, 12:37 pm, "Mark Rae [MVP]" <> wrote:
    >> "Lit" <> wrote in message
    >>
    >> news:%...
    >>
    >> > Your code works fine on my machine.

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

    >>
    >> Same here.
    >>
    >> --
    >> Mark Rae
    >> ASP.NET MVPhttp://www.markrae.net

    >
    >
    Lit, Sep 6, 2007
    #8
  9. 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" <> wrote in message
    news:...
    > 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
    >
    > On Sep 6, 12:37 pm, "Mark Rae [MVP]" <> wrote:
    >> "Lit" <> wrote in message
    >>
    >> news:%...
    >>
    >> > Your code works fine on my machine.

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

    >>
    >> Same here.
    >>
    >> --
    >> Mark Rae
    >> ASP.NET MVPhttp://www.markrae.net

    >
    >
    George Ter-Saakov, Sep 6, 2007
    #9
  10. page_load event fires twice in firefox only

    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


    "DBLWizard" <> wrote in message
    news:...

    Previous Posts In This Thread:

    On Thursday, September 06, 2007 12:53 PM
    DBLWizard wrote:

    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

    On Thursday, September 06, 2007 1:45 PM
    George Ter-Saakov wrote:

    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.



    "DBLWizard" <> wrote in message
    news:...

    On Thursday, September 06, 2007 2:06 PM
    Lit wrote:

    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


    "DBLWizard" <> wrote in message
    news:...

    On Thursday, September 06, 2007 2:21 PM
    DBLWizard wrote:

    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

    On Sep 6, 11:45 am, "George Ter-Saakov" <> wrote:

    On Thursday, September 06, 2007 2:37 PM
    Mark Rae [MVP] wrote:

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


    Same here.


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

    On Thursday, September 06, 2007 2:48 PM
    George Ter-Saakov wrote:

    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.



    "DBLWizard" <> wrote in message
    news:...

    On Thursday, September 06, 2007 3:00 PM
    DBLWizard wrote:

    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

    On Sep 6, 12:37 pm, "Mark Rae [MVP]" <> wrote:

    On Thursday, September 06, 2007 3:15 PM
    Lit wrote:

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

    Lit

    On Thursday, September 06, 2007 3:44 PM
    George Ter-Saakov wrote:

    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.



    "DBLWizard" <> wrote in message
    news:...


    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
    shailesh patel, Apr 2, 2010
    #10
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Tony Dong

    asp.net page load twice problem

    Tony Dong, Jun 2, 2005, in forum: ASP .Net
    Replies:
    11
    Views:
    39,024
    BillFR
    Sep 1, 2011
  2. Xavier Osa
    Replies:
    0
    Views:
    618
    Xavier Osa
    Jan 9, 2004
  3. Samy
    Replies:
    2
    Views:
    1,336
  4. michaeltorus
    Replies:
    0
    Views:
    689
    michaeltorus
    Nov 25, 2005
  5. Greg
    Replies:
    4
    Views:
    1,150
Loading...

Share This Page