Reputation: 4095
On_Load is being called twice in a page. After using Firebug I found that it requests
http://localhost/default.aspx
then it does another request to
http://localhost/default.aspx#ced3db
I search for "#ced3db"
and found it in a <table>
in the page. When I remove its background attribute, the problem disapears.
<table width="430" height="281" border="0"
background="#ced3db" cellpadding="0" cellspacing="0">
I used a style attribute to avoid requesting the page twice. But, I still need to know: why there are two requests being made? I would like to understand the root cause to avoid re-requesting a page, because it can make any website slower.
Edit: The question has nothing to do with inline styles vs. using CSS files. It is about avoiding unintentionally re-requesting the page for performance reasons.
Note: On_Load can be called twice for several reasons, See ASP.NET Page.OnLoad executes twice
<img src="#"> or <img src="">
Upvotes: 3
Views: 156
Reputation: 218877
I'm pretty sure the background
attribute for a table
element expects a URL of an image. (I don't think it's even a proper attribute for that element, or at least I've never seen it used. Might have browser-specific behavior.)
If that's the case, then this kind of makes sense. At the end of the question you note:
- The page or master page contains
<img src="#">
or<img src="">
So that seems to be what's happening here. The browser is interpreting that color tag as a URL and making a request back to the server resource to try to fetch it, since a hash URL by itself defaults to the current page. In an anchor tag it would just move the focus to that tag on the page, but in a resource-reference tag (such as an img
, but in this case an attribute on table
which expects a URL) it has to make another request.
Update: A little Googling on the attribute turns up a number of pages similar to this one, which seem to indicate that it is expecting a URL.
Indeed, the table
element doesn't seem to officially have a background
attribute. At least not in HTML 4 or HTML 5.
Upvotes: 3
Reputation: 21003
The background
attribute does not accept hex colors as inputs. You should be using CSS anyway. Use the background-color
CSS property instead.
See this fiddle for the background
attribute not working.
And this working with the CSS property.
Upvotes: -1