The_AlienCoder
The_AlienCoder

Reputation: 577

Page load fires twice on Firefox

OK, first some background: I have a page showing the number of hits(or views) of any selected item. The hit counter procedure that is called at every page load i.e

if (Request.QueryString.HasKeys())
{
    // get item id from icoming url e.g details.aspx?itemid=26            

    string itemid = Request.Params["itemid"];

    if (!Page.IsPostBack)
    {
        countHit(itemid);
    }
}

The problem: my expectation was that the counter would be increased by 1 on every page load but the counters on my datalist and formview are always behind and stepped by 2 i.e

instead of 1, 2, 3, 4, it's 0, 2 , 4, 6.

It seems that the page load is firing twice. Later I discovered that this only happens when you are using Mozilla Firefox. The page behaves fine with other browsers like IE

This becoming quite frustrating.

Upvotes: 6

Views: 6906

Answers (9)

Paul Suart
Paul Suart

Reputation: 6713

I've seen Page_Load fire twice if you have an <asp:Image> or an <img runat="server"> on the page that doesn't have its src attribute specified.

Could be worth a look.

Upvotes: 24

Mohammad Fahimi - IRI
Mohammad Fahimi - IRI

Reputation: 11

I had this problem too. I found that AVG antivirus toolbar on firefox makes another hit to that page and I had 2 hits per refresh.

Just go to Tools>Add-ons and disable AVG toolbar if you have it. Otherwise it may caused by another extension like one added by antiviruses or other software.

Good luck

Upvotes: 1

anand
anand

Reputation: 101

Anchor tag with empty href i.e. href="" is also an issue. Use href="#" wherever URL is not required in an anchor tag.

Upvotes: 0

andy
andy

Reputation: 21

We ran into a similar problem where fiddler showed that one of our pages loaded twice. This only happened in Firefox and Chrome. The solution was to change:

background-image:url('');

to

background-image:none;

Upvotes: 2

Orlando
Orlando

Reputation: 147

I had this problem as well.. in my case firebug was causing the extra call.

Upvotes: 2

shailesh
shailesh

Reputation: 5023

I am aware of following things.

If you have img control with empty string assigned to src attribute. 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.

If you have empty src attribute set to script.

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

Upvotes: 3

Hans Kesting
Hans Kesting

Reputation: 39358

Usually the reason that the page_load is fired twice is that you have AutoEventWireup=true in the ascx/aspx AND you bind the Load event to the Page_Load method explicitly (in the codebehind).

But then you should see this behavior in all browsers.

Upvotes: 0

mxmissile
mxmissile

Reputation: 11681

Try turning off FireBug if you have it enabled.

Upvotes: 1

Colin Newell
Colin Newell

Reputation: 3163

The most likely reason is that you're calling the procedure twice.

Upvotes: 0

Related Questions