6

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.

Toribio
  • 3,963
  • 3
  • 34
  • 48
The_AlienCoder
  • 577
  • 6
  • 19

9 Answers9

24

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.

Paul Suart
  • 6,505
  • 7
  • 44
  • 65
3

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

shailesh
  • 5,013
  • 5
  • 23
  • 22
2

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

Orlando
  • 147
  • 1
  • 9
2

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;
DarthJDG
  • 16,511
  • 11
  • 49
  • 56
andy
  • 21
  • 1
1

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

McGarnagle
  • 101,349
  • 31
  • 229
  • 260
1

Try turning off FireBug if you have it enabled.

mxmissile
  • 11,464
  • 3
  • 53
  • 79
0

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

Colin Newell
  • 3,073
  • 1
  • 22
  • 36
  • I thought so too. But theres nothing Im doing at page_load other than setting the @id parameter for my sql datasource. – The_AlienCoder Jan 28 '10 at 11:18
  • Try logging the call so that you see whenever it is called. – Colin Newell Jan 28 '10 at 13:06
  • You wont believe this but it seems the problem lies with Mozilla Firefox. The page works fine in IE and other browsers...seems mozilla is making duplicate calls to the server !!...Has any1 ever encountered such a scenario?(FF making duplicate calls) – The_AlienCoder Jan 28 '10 at 18:21
  • You might want to update your main question so that people can see the actual problem. One thing I'd suggest you do is install the Firebug add in for Firefox and have a look at the network traffic to see what's happening. My one guess is a redirect but honestly I don't know. – Colin Newell Jan 29 '10 at 00:16
0

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.

Hans Kesting
  • 38,117
  • 9
  • 79
  • 111
0

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

DarthJDG
  • 16,511
  • 11
  • 49
  • 56
anand
  • 81
  • 1
  • 9
  • In another page I had embedded Object tag with empty src attribute, i.e. src="" . This is also an issue. So I can conclude that any empty url reference, be it src, url, href etc are the culprits :) – anand Apr 20 '11 at 15:38