The_AlienCoder The_AlienCoder - 5 months ago 22
ASP.NET (C#) Question

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)

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.


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.