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
- AutoEventWireUp is true and you override On_Load.
- A user control contains AutoEventWireUp with true. Did not try that.
- The page or master page contains
<img src="#"> or <img src="">
I’m pretty sure the
backgroundattribute for atableelement 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:
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 ontablewhich 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
tableelement doesn’t seem to officially have abackgroundattribute. At least not in HTML 4 or HTML 5.