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)
{
开发者_StackOverflow社区 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.
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.
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
I had this problem as well.. in my case firebug was causing the extra call.
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;
Try turning off FireBug if you have it enabled.
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
The most likely reason is that you're calling the procedure twice.
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.
Anchor tag with empty href i.e. href=""
is also an issue. Use href="#"
wherever URL is not required in an anchor tag.
精彩评论