38

Does anyone have any problems with Page_Load being executed twice in Google Chrome? It's a short question, i do not know what else to explain...

I have a simple asp.net page and in Firefox and IE all it's working fine. But in Chrome the Page_Load is fired twice...

Anyone has any ideas why?

Later EDIT: - what is strange is that i have 4 repeaters... binded with random values. The random methods are twice fired (because of page loaded twice) but the repeaters takes the INITIALLY values...so, the 2nd post back is somehow raised after the rendering step.

3rd edit: It happens ONLY at the refresh!

Solution (in my case): There was an empty img src, and that was the cause

Cristian Boariu
  • 9,603
  • 14
  • 91
  • 162
  • Is this happening for *all pages* or just *a specific page*. If it's all pages, maybe file a bug report with Google? – Greg Jan 05 '10 at 21:18
  • Unfortunately, it's not for all pages...It's just for a specific one, so i think it's something minor on this page....or major:) – Cristian Boariu Jan 05 '10 at 21:24
  • 1
    In that case, I'd use a standard troubleshooting technique. Slowly strip stuff out of the page until the problem goes away. – Greg Jan 05 '10 at 21:29
  • Yes Greg, i use this techique sometimes, but in this case there is a very complex page, with 4 repeaters and a lot of code behind it... – Cristian Boariu Jan 05 '10 at 22:00

22 Answers22

44

I notice this same issue in IE if the page contains img tags that don't have a src attribute (or the src is empty, etc). Not sure if Chrome does the same thing, but worth checking, right?

Chris Shaffer
  • 32,199
  • 5
  • 49
  • 61
  • Now that you mention this, I have seen it during this circumstance. – Greg Jan 06 '10 at 17:34
  • 5
    Chris, your presumption was awesome!!!!! There was an empty img src, and that was the cause. Thanks a lot! – Cristian Boariu Jan 08 '10 at 16:12
  • 1
    I had the same nightmare bug! For me it was a tag that came along with a masterpage I had to use. – Peter Apr 09 '10 at 09:48
  • I had the exact same issue. Thanks for the info! Does anyone know the reasoning behind this behavior of certain browsers for missing src attributes? – Mark Freedman Jul 22 '11 at 21:12
  • @Mark - Total assumption on my part, nothing to back it up; Maybe it is because the URLs on a page are being treated as relative, so a blank URL for an image src is taken as "" relative to the requested page, ending up with the requested page again. Like I said, I'm just making that up though :) – Chris Shaffer Jul 26 '11 at 02:07
  • 1
    @Chris - Sounds like a good educated guess. If I hear of anything definitive, I'll post it here. – Mark Freedman Jul 28 '11 at 17:51
  • I had the same thing happen when I had a `` to try and avoid having a favicon.ico file. Thanks for the tip! – Chris Conway Mar 13 '12 at 18:15
  • Holy smokes was this a lifesaver! Couldn't figure out why Safari did a callback followed by a postback. This corrected it. Got my upvote. – Bob Mc Jun 16 '12 at 02:05
  • My problem was `src = "#"` making Chrome & iPad browsers (Safari & Dolphin) fire twice. – Nick Dec 27 '12 at 00:25
  • You deserve a medal, sir! – quangteo.media Sep 27 '18 at 02:05
14

For me the problem was because of the extension Firebug Lite for Google Chrome. Once deactivated the page only loads once.

Johann
  • 12,158
  • 11
  • 62
  • 89
7

I had a very similar problem: Chrome and Firefox loading the page twice, Internet Explorer loading it once.

The problem was because of my .htaccess:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [QSA,L]

When the browsers were requesting a favicon.ico, my index.php page was called, thus creating a double access to the server. My solution was to create a favicon.ico, although I could also had index.php handle that special case, or even .htaccess, but I needed a favicon.ico anyway :)

sth
  • 222,467
  • 53
  • 283
  • 367
miracl
  • 1
  • 1
  • 1
  • You, sir, deserve a medal. I was banging my head against the wall but now you say it, it's so obvious! What's more annoying is I've come across this before but didn't put 2+2 together. Thanks :) – ledneb Feb 13 '11 at 23:21
  • Yep, I initially started troubleshooting this issue as if it was a threading issue in my asp.net code, and it turns out it was the damn favicon.ico causing the problem, which coincidently was not visible using the built in developer tools - I needed to use the 'Live HTTP Headers' plugin for Chrome to see the both requests.. I would also agree that @miracl deserves a medal for this! thank you :) – Steve Rathbone Oct 18 '14 at 07:23
6

I had the same stupid problem. Page loads twice and the updates went blank.

Thanks to this posting I checked my CSS sheet.

I removed this line:

body { background-image: url(); }

That was the problem

Edwin
  • 61
  • 1
  • 1
4

I recently had this issue with Chrome rendering twice too, the cause of this issue is

<iframe src="#"></iframe>

once I set it to

<iframe></iframe>

or completely remove iframe then the double rendering no longer appears.

Chihung Yu
  • 1,234
  • 10
  • 11
2

In addition to Chris Shaffer's answer which got me on the right track, I'd like to add that in my case there was also a <script> tag with an empty src that caused the problem.

Perhaps it applies to all elements with an empty src.

mflodin
  • 1,093
  • 1
  • 12
  • 22
1

This may be a problem with one of the extensions/plugins. Try out the incognito mode - this helped me once.

Hexodus
  • 12,361
  • 6
  • 53
  • 72
1

Gecko based browsers apparently do this when the markup is incorrect. That means XHTML AND CSS.

Here is a great post about the issue: http://www.110mb.com/forum/how-to-stop-firefox-dual-pageloads-t27704.0.html

That's why some of you guys are getting the problem when you have a blank src attribute or a blank href attribute. Incorrect syntax, the browser reads it as an "error". I guess it's a more unobtrusive type of error that you would otherwise not even notice, but due to the nature of the page you're working on it's become apparent and presented itself as a rather obtrusive problem.

What certain browsers consider to be an 'error' and what is 'passable' is probably slightly different too, that would explain why some of you are having the problem in FF and not in Chrome and visa versa.

Just be thankful you're not in my shoes. I've got a page that's sending an email out twice due to this issue and there's no way I can fix the bad markup because there's just simply too much of it to fix being generated in far too many places, a lot of the CSS and HTML issues are dynamically driven too unfortunately.

I still don't understand the reasoning behind it grabbing the page twice though when it encounters non-compliant issues of this nature though.

Mark
  • 45
  • 2
  • 2
  • 10
1

Base on Johann's reply, I check and disable each extension in google chrome and discover the flash extension cause my browser reload twice. After remove it, the problem is solved!!

Brady Huang
  • 1,852
  • 20
  • 23
1

In my case it was this <link rel="shortcut icon" href="#" /> tag in the head of my index.html file:

<html lang="en">
  <head>
  ...
  <link rel="shortcut icon" href="#" />
  ...
  </head>
  ...
</html>

I just removed that line and problem solved.

Andrew F.
  • 453
  • 1
  • 6
  • 15
0

Ran into the same issue. I was using DOM Snitch.

I disabled it and it immediately stopped posting back twice.

After looking at it, it seems to contain 2 tags without an href attribute. Because it's a Chrome extension it's injected into the DOM at the client and I suppose this causes a Webforms page to post back twice.

On the off chance someone sees this, be sure to check any extensions and/or plugins you are using.

William
  • 1,517
  • 1
  • 12
  • 26
0

I had the same issue. However my "mistake" was located in my css file.

I was using .htaccess to rewrite everything back to my root folder but used

background-image: url('../img/login_facebook.png')

in my css file. I removed the .. and the problem was solved.

0

So far I've used Chrome to test ASP.NET pages many times and never encountered this. What are you doing client-side that could cause this? Are you doing any AJAX stuff?

Randolpho
  • 55,384
  • 17
  • 145
  • 179
0

I noticed that this started happening to me when I switched to Chrome v.4, the developer's channel, so that i could start using extensions. Didn't seem to be a problem with v.3, the stable version.

Adam Crossland
  • 14,198
  • 3
  • 44
  • 54
  • 1
    I have this problem in 3.0 and dev too – Cristian Boariu Jan 05 '10 at 21:11
  • seems to be extensions firing this off. Not sure which one though. Tried to use fiddler but no culprit was evident. using firebug there is a googlechrome.js that gets injected into the page. Not sure what this does as access is denied. – skyfoot Jul 08 '11 at 15:24
0

In your Page_Load, check the value of Page.IsPostBack and Page.IsCallback to see if they differ between the two calls. If they're different, it could be some javascript reexecuting or chrome following a redirect twice or something odd like that.

Greg
  • 16,540
  • 9
  • 51
  • 97
  • 1
    Also check ScriptManager.GetCurrent(this).IsInAsyncPostBack to see if one of the loads is because of an AsyncPostBack. Maybe one of your Ajax calls is forcing a load. This might be caused by an UpdatePanel with update set to always. I don't think this situation will register with Page.IsCallback. – Joseph Yaduvanshi Jan 05 '10 at 21:41
  • Checked this in page load: bool test = ScriptManager.GetCurrent(this).IsInAsyncPostBack; with debug mode and it's false for both calls; – Cristian Boariu Jan 05 '10 at 21:53
0

I encountered a similar problem with PHP and Firefox.

The problem was coming from a faulty style definition that Firefox interpreted to reload the page. I cannot remember exactly what it was but int the idea, could be something like

.my_class    { background: url(#); }

I would advice to try to isolate first your CSS and then your HTML sections to check if the problem might come from it.

Benoît Vidis
  • 3,908
  • 2
  • 23
  • 24
0

If you set your image tag src to # or empty it will cause twice pageload calling, i faced this on chrome and before on firefox.

you can put any char or string value instead of empty or # to solve this issue.

Amr Elgarhy
  • 66,568
  • 69
  • 184
  • 301
0

It also doesnt like empty href's

I had an empty favicon link tag and it did the same thing. Whoever said about the empty src put me onto that, just stripped out everything until it started working

0

I'm also having this issue.

Funny, I added "visible=false" to the whole "form" tag making the page totally empty - it still loads twice. I also tweaked the DOCTYPE, checked the img-tags for empty sources etc. etc. etc.

It still loads twice.

BUT I noticed that this happens on "localhost" only. Remote websites work fine.

I thought may be is has something to do with DNS, but "127.0.0.1" also loads twice. This drives me nuts...

Alex from Jitbit
  • 53,710
  • 19
  • 160
  • 149
0

Here is another great article on why this occurs: https://www.nczonline.net/blog/2009/11/30/empty-image-src-can-destroy-your-site/

I was getting the same error using Chrome in an ASP.NET site. I was getting the page life-cycle firing again with IsPostBack set to False.

This caused all sorts of issues for me.

Guy Lowe
  • 2,115
  • 1
  • 27
  • 37
0

I just had the same issue, and once I shut down the JSON Viewer extension, problem was solved. I can recommend this extension for viewing JSON's without the extra request as side-effect: https://chrome.google.com/webstore/detail/json-formatter/bcjindcccaagfpapjjmafapmmgkkhgoa

RoyBass
  • 26
  • 2
-2

I believe it is just how Google Chrome works. I put some code on my index page to write to a file with the file name that was loaded, and every time I load the page (using refresh or a new window) it puts 2 results in the file.

EDIT: I renamed my index file to test.php and ran it again. This time it only had one result. This problem is pissing me off.

EDIT: I renamed my file back to index.php and ran it. Same problem. Then I renamed my .htaccess (for mod_rewrite) to htaccess so it wouldn't be parsed and the problem is gone. After I found this out, I disabled url rewriting in the .htaccess file and the problem was still gone (finally). I did one more test (if people are still reading this crap) and found that google loads the page twice when you redirect from the .htaccess file. I found a little workaround that seems to fix the problem.

Not sure if this applies to asp.net. I only know php coding and apache servers.

Kyle
  • 1
  • 1