Page_load event fires twice with FireFox only

I came across weird behavior of Firefox 3.0.X that submits forms twice.  Let me explain what I have seen.

  • Main.ascx has a reference of UC1.ascx
  • Main.ascx also has a UC2.ascx control reference.

When I make the request to PageX.aspx that contains Join.ascx control.  Here is the page execution cycle I am seeing.

  • Page_Load (Main.ascx) Page.IsPostBack is false
  • Page_Load (UC1.ascx) Page.IsPostBack is false
  • Page_Load (UC2.ascx) Page.IsPostBack is false
  • Page_Load (Main.ascx) Page.IsPostBack is false
  • Page_Load (UC1.ascx) Page.IsPostBack is false
  • Page_Load (UC2.ascx) Page.IsPostBack is false

When I click on some control like button that triggers the page post back, I am seeing

  • Page_Load (Main.ascx) Page.IsPostBack is true
  • Page_Load (UC1.ascx) Page.IsPostBack is true
  • Page_Load (UC2.ascx) Page.IsPostBack is true
  • Page_Load (Main.ascx)  Page.IsPostBack is false  (this one creates a problem. In my case code clears some session value if page postback is false)
  • Page_Load (UC1.ascx)     Page.IsPostBack is false
  • Page_Load (UC2.ascx)    Page.IsPostBack is false

You may have noticed that Page_Load executed twice.  It’s really bad things from performance point of view and also for web analysis tool that tracks page hit (may be a good thing if you have custom code that increments counter in Page_Load so you will have page hit 2x(double page hit value) but actual value is x if user uses firefox 3.0.x).

But what causes the Firefox to execute the page request twice?  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”>

Worst thing is that if you have both img and link into page, page gets executed three times(first normal, second for empty src attribute and third for empty href attribute).

The reason why Firefox is doing that when It finds empty src attribute it makes additional request to the same page to resolve the URI as per standard behavior defined in RFC 3986 – Uniform Resource Identifiers section 5.2 section 5.4.  So Firefox isn’t bad it follows the standard but that creates the problem for us(specially for me who is in Flex team and assigned weird bug that only happening in Firefox and took my almost 1.5 days to figure this out L).

Nice thing is that they have fixed this behavior in new version of Firefox 3.6.X.

CAUTION: Don’t leave SRC attribute empty. If you want to assign imageURL in code behind based on some condition, you can still assign very tiny pixel image(that you barely see) in aspx page so that we have at least image assigned until your website support Firefox 3.0.x.

Posted in Microsoft Technology Tagged with: ,
2 comments on “Page_load event fires twice with FireFox only
  1. Safi says:

    you save my time


  2. Morpheus says:

    Oh, thanks a lot. This article saves my time.

Ads is a trading site of World of Limited. Outback Direct is the official Outback Consumer Warranty, Parts and Accessory Partners for the UK. We currently hold in stock 1000’s of parts and accessories for current and older Outback barbecues. We endeavour to ensure rapid and secure product delivery the length and breadth of mainland United Kingdom, this factor coupled with our excellent customer service has led to the market position we currently enjoy.
outback barbecue
omega 300 gas barbecue
Omega 250 Gas Hooded BBQ
------------------------------------------------------------ Silver Sky Imports is a unique online marketplace that offers unique handicrafts from Tibet and Nepal. Launched in 2003, Silver Sky Imports is currently the largest supplier of handmade items from the Himalayas. We specialize in the largest variety of Tibetan Singing Bowls and Crystal Singing Bowls online and include individual sound samples, pictures and descriptions for each bowl. Some of our other products include Tibetan Prayer Flags, Tingshas, Bell and Dorje, Incense, Felted Wool Handbags, Wood Masks, Prayer Wheels, Gongs, Bronze Statues, and Tibetan Meditation Rugs. monks
------------------------------------------------------------ Airpush, a mobile ad network that is only two years old, has quickly grown to one with over 5,000 advertisers. One thing they've heard from that sea of advertisers over the past 12 months, and especially over the past six, is that real-time bidding (RTB) capabilities are now a must. To answer those needs, the company today unveiled AirDSP, a platform meant to easily connect advertisers to RTB exchanges. Read more: Mobile RTB
------------------------------------------------------------ Danish site about electronic cigarettes E Cigarette, Electronic Cigarette and E Cigarettes e cigaret
------------------------------------------------------------ drugrisk​ recall ​informat​ion​ drugrisk​ yaz​