Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 658
The_AlienCoder Avatar asked Jan 28 '10 09:01

The_AlienCoder


6 Answers

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.

like image 75
Paul Suart Avatar answered Nov 11 '22 20:11

Paul Suart


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

like image 3
shailesh Avatar answered Nov 11 '22 20:11

shailesh


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

like image 2
Orlando Avatar answered Nov 11 '22 20:11

Orlando


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;
like image 2
andy Avatar answered Nov 11 '22 20:11

andy


Try turning off FireBug if you have it enabled.

like image 1
mxmissile Avatar answered Nov 11 '22 18:11

mxmissile


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

like image 1
Mohammad Fahimi - IRI Avatar answered Nov 11 '22 18:11

Mohammad Fahimi - IRI