views:

934

answers:

13

Hi guys, 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

A: 

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
I have ajax stuff inside the page BUT for my question, i only REFRESH the entire page and not touch any button inside an ajax area...so, normal refresh.
Cristian Boariu
Does it happen the first time you navigate to the page, or only after a refresh?
Randolpho
Very good question. It happens only after refresh!
Cristian Boariu
Sounds like you may have some sort of onunload event running that other browsers are swallowing.
Randolpho
A: 

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
I have this problem in 3.0 and dev too
Cristian Boariu
A: 

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
Both times: .IsPostBack=false; .IsCallback=false.....
Cristian Boariu
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.
Jim Schubert
Checked this in page load: bool test = ScriptManager.GetCurrent(this).IsInAsyncPostBack; with debug mode and it's false for both calls;
Cristian Boariu
+10  A: 

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
Now that you mention this, I have seen it during this circumstance.
Greg
Chris, your presumption was awesome!!!!! There was an empty img src, and that was the cause. Thanks a lot!
Cristian Boariu
I had the same nightmare bug! For me it was a <input type="image" src=""> tag that came along with a masterpage I had to use.
Peter
A: 

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.

Benoit Vidis
A: 

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
and in Firefox all it's ok?
Cristian Boariu
No problem in firefox.
Kyle
A: 

Kyle. What was the solution? I have this problem too, and i want to use rewrite.

babosc
A: 

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
A: 

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

Horse
A: 

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
A: 

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...

jitbit
A: 

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 :)

miracl
A: 

Thank you! You saved us a nightmare! :0

oZo