CSS not applied on first loadhttp://forums.asp.net/t/1180199.aspx/1?CSS+not+applied+on+first+loadTue, 21 Feb 2012 20:42:01 -050011801991998421http://forums.asp.net/p/1180199/1998421.aspx/1?CSS+not+applied+on+first+loadCSS not applied on first load <p>Hello everyone,</p> <p>&nbsp;I am not sure if I am posting this to the right area but here goes:</p> <p>I have a problem that I have not seen before.&nbsp; I have a Web Project in .net 2.0 (not website)&nbsp; I am using Visual Studio 2005.&nbsp; I have the following in my &lt;head&gt; section:</p> <font size="2"> <p></font><font color="#0000ff" size="2">&lt;</font><font color="#a31515" size="2">title</font><font color="#0000ff" size="2">&gt;</font><font size="2">Payment Processing</font><font color="#0000ff" size="2">&lt;/</font><font color="#a31515" size="2">title</font><font color="#0000ff" size="2">&gt;</p> </font><font size="2"> <p></font><font color="#0000ff" size="2">&lt;</font><font color="#a31515" size="2">link</font><font size="2"> </font><font color="#ff0000" size="2">href</font><font color="#0000ff" size="2">=&quot;styles.css&quot;</font><font size="2"> </font><font color="#ff0000" size="2">rel</font><font color="#0000ff" size="2">=&quot;stylesheet&quot;</font><font size="2"> </font><font color="#ff0000" size="2">type</font><font color="#0000ff" size="2">=&quot;text/css&quot;</font><font size="2"> </font><font color="#0000ff" size="2">/&gt;</p> </font><font size="2"> <p></font><font color="#0000ff" size="2">&lt;</font><font color="#a31515" size="2">script</font><font size="2"> </font><font color="#ff0000" size="2">type</font><font color="#0000ff" size="2">=&quot;text/javascript&quot;</font><font size="2"> </font><font color="#ff0000" size="2">language</font><font color="#0000ff" size="2">=&quot;javascript&quot;</font><font size="2"> </font><font color="#ff0000" size="2">src</font><font color="#0000ff" size="2">=&quot;js/maskedit.js&quot;&gt;&lt;/</font><font color="#a31515" size="2">script</font><font color="#0000ff" size="2">&gt;</p> </font><font size="2"> <p></font><font color="#0000ff" size="2">&lt;</font><font color="#a31515" size="2">script</font><font size="2"> </font><font color="#ff0000" size="2">type</font><font color="#0000ff" size="2">=&quot;text/javascript&quot;</font><font size="2"> </font><font color="#ff0000" size="2">language</font><font color="#0000ff" size="2">=&quot;javascript&quot;</font><font size="2"> </font><font color="#ff0000" size="2">src</font><font color="#0000ff" size="2">=&quot;js/dateFunctions.js&quot;&gt;&lt;/</font><font color="#a31515" size="2">script</font><font color="#0000ff" size="2">&gt;</font></p> <p><font color="#0000ff" size="2"></font>&nbsp;</p> <p><font color="#0000ff" size="2">When the page first loads, either in the local ASP.Net Development Server or when published to IIS, all styles are completly ignored.&nbsp; I do kow for a fact that the page is loading the styles because I am using fiddler.&nbsp; Fiddler tells me the styles.css is loading.&nbsp; I know for a fact that all the styles are correct because if I press F5 to refresh the page the styles are applied perfectly.&nbsp; This behavior occurs on two different PCS (when published to IIS 5.1)&nbsp; However, when published to IIS 6.0, the styles are applied perfectly.&nbsp; Is there any rhyme or reason for this?&nbsp; Ultimately, I only need it to work under IIS 6 but I would like to know why it doesn't work in IIS 5.1 and the .net Development Server.&nbsp; </font></p> <p><font color="#0000ff" size="2">Any ideas?</font></p> <p><font color="#0000ff" size="2">Thanks,</font></p> <p><font color="#0000ff" size="2">John</p> </font> 2007-11-09T14:21:19-05:001998527http://forums.asp.net/p/1180199/1998527.aspx/1?Re+CSS+not+applied+on+first+loadRe: CSS not applied on first load <p>Try forcing a cache refresh on your browser (ctrl &#43; F5), there is a chance your browser may be using an older cached version of the StyleSheet.&nbsp;</p> 2007-11-09T15:07:27-05:001998549http://forums.asp.net/p/1180199/1998549.aspx/1?Re+CSS+not+applied+on+first+loadRe: CSS not applied on first load <p>Hey Adam, Thanks for the reply.&nbsp; I went ahead and tried what you said but that didn't work. Going down that road I went ahead and deleted all my temp internet files, closed the browser and launched the project again.&nbsp; The same thing occured.&nbsp; Also, this did occur on a different pc and continues to occur.&nbsp; The issue is occuring in Firefox as well.</p> <p>Thanks again for the advise though,</p> <p>John</p> 2007-11-09T15:16:04-05:001998643http://forums.asp.net/p/1180199/1998643.aspx/1?Re+CSS+not+applied+on+first+loadRe: CSS not applied on first load <p>Try loading the StyleSheet into your browser (http://yourServerName/yourAppName/StyleSheet.css). </p> <p>Does it work? Do you receive the correct StyleSheet.css?&nbsp;</p> 2007-11-09T15:48:49-05:001998676http://forums.asp.net/p/1180199/1998676.aspx/1?Re+CSS+not+applied+on+first+loadRe: CSS not applied on first load <p>Hey Adam,</p> <p>I just double checked and yes I am.&nbsp; I also loaded it with Fiddler running and viewed the css file from there and matched it up.&nbsp; Fiddler is loading the same file when I launch the app as well as when I type it into the address bar.&nbsp; It is really an odd issue and its something that I dont need to fix because if I refresh the page it applys the styles correctly.&nbsp; Even when the styles are not applied I do know it is loading the stylesheet because of Fiddler. My first guess was the style sheet was not loading at all but Fiddler proved me wrong.&nbsp; In our production environemt with IIS 6 I dont experience the problem.&nbsp;&nbsp;Its really strange.&nbsp; </p> <p>&nbsp;thanks again,</p> <p>John</p> 2007-11-09T16:04:00-05:001998770http://forums.asp.net/p/1180199/1998770.aspx/1?Re+CSS+not+applied+on+first+loadRe: CSS not applied on first load <p>Does your StyleSheet contain any bugs? Try running your site on Firefox with the <a href="http://www.getfirebug.com/">Firebug </a>add-on enabled - if your StyleSheet has errors this little add-on usually catches them.</p> <p>Are you using the site through the same browser when viewing the server and local sites?<br> </p> 2007-11-09T16:48:31-05:001998808http://forums.asp.net/p/1180199/1998808.aspx/1?Re+CSS+not+applied+on+first+loadRe: CSS not applied on first load <p>I didnt notice any errors in the style sheet before (I have firebug installed previously because it is great!)&nbsp; I went into Firefox just now to double check and Firefox did an update. Problem is no longer occuring in the latest version of firefox but is occuring in I.E.&nbsp; I was using the site though different browsers before for both local and server sites (Used both I.E. 7 and Firefox)</p> <p>&nbsp;Thanks,</p> <p>John</p> 2007-11-09T17:06:35-05:001998947http://forums.asp.net/p/1180199/1998947.aspx/1?Re+CSS+not+applied+on+first+loadRe: CSS not applied on first load <p>That's so weird! </p> <p>Let's rehash this problem: </p> <p>Your StyleSheets aren't applied to your site on the first load, but on subsiquent loads your StyleSheets are loaded, and your site is rendered properly. This behavior happens on both IE and Firefox. We can run the <b><i>local</i> </b>and <b><i>deployed</i> </b>version of the same site in the<b> </b><i><b>same browser</b>, </i>but the <b><i>local </i></b>site always fails to render the site properly (<i>presumably it's failing to load the StyleSheet</i>), and the <b><i>deployed </i></b>version always works correctly.</p> <p>Does that about sum it up? &nbsp;</p> <p>By chance, are you using ASP.NET Themes? Are you dynamically adding styles through your code behind?</p> 2007-11-09T18:20:46-05:001998994http://forums.asp.net/p/1180199/1998994.aspx/1?Re+CSS+not+applied+on+first+loadRe: CSS not applied on first load <p>Hey Mark,</p> <p>Yes, its the weirdest thing ever!</p> <p>&nbsp;&quot;Your StyleSheets aren't applied to your site on the first load, but on subsiquent loads your StyleSheets are loaded, and your site is rendered properly&quot;&nbsp;&nbsp; - Yes</p> <p>&quot;This behavior happens on both IE and Firefox&quot;&nbsp; - Before was happening in both IE and Firefox until Firefox did an update.&nbsp; Now only happening in IE.&nbsp; I just double checked this and yes, only happening in IE.</p> <p>&quot;We can run the <b><i>local</i> </b>and <b><i>deployed</i> </b>version of the same site in the<b> </b><i><b>same browser</b>, </i>but the <b><i>local </i></b>site always fails to render the site properly (<i>presumably it's failing to load the StyleSheet</i>), and the <b><i>deployed </i></b>version always works correctly.&quot;&nbsp;&nbsp; - Yes, fails to apply the stylesheet on first load in Internet Explorer only.&nbsp; Deployed version always works correctly only in IIS 6.0 (But this might not be an IIS 6 issue as II6 is on a different box, II6 5.1 and the .net Development server are both local.&nbsp; Fiddler shows the style sheet being accessed when the page loads the first and subsquent times, IE just doens't apply it the first time.&nbsp;&nbsp;</p> <p>So yup, that about sums it up.&nbsp; Themes are not being used and the styles are being applied though code behind via two methods:</p> <font size="2"> <p>td1.Style.Add(</font><font color="#a31515" size="2">&quot;border-bottom&quot;</font><font size="2">, </font><font color="#a31515" size="2">&quot;1px solid black;&quot;</font><font size="2">);&nbsp; OR default items like:</font></p> <font color="#a31515" size="2"> <p>A</font><font size="2"> { </font><font color="#ff0000" size="2">color</font><font size="2">:</font><font color="#0000ff" size="2">#000080</font><font size="2">; </font><font color="#ff0000" size="2">text-decoration</font><font size="2">:</font><font color="#0000ff" size="2">underline</font><font size="2">; } or</font></p> <font size="2"><font color="#a31515" size="2">.legend</font><font size="2"> </font> </font><font size="2"> <p>{</p> </font><font color="#ff0000" size="2">font-family</font><font size="2">:</font><font color="#0000ff" size="2">Verdana</font><font size="2">;</font><font size="2"> <p></font><font color="#ff0000" size="2">color</font><font size="2">:</font><font color="#0000ff" size="2">Maroon</font><font size="2">;</p> <p>}</p> </font> <p><font size="2">The first, Style.Add() is rendering correct on first load and each additional loads.&nbsp; The other items as defined in the style sheet are not getting rendered.&nbsp; However, I just noticed something more interesting.&nbsp; The only styles that are not applied are styles that get appplied to text and links.&nbsp; But as I look at this further, I think the reverse is happening but in my mind I think its not loading correct the first time when it looks like it might be the other way around.&nbsp; Example:</font></p> <font color="#0000ff" size="2"> <p>&lt;</font><font color="#a31515" size="2">td</font><font size="2"> </font><font color="#ff0000" size="2">align</font><font color="#0000ff" size="2">=&quot;right&quot;</font><font size="2"> </font><font color="#ff0000" size="2">style</font><font color="#0000ff" size="2">=&quot;height: 22px&quot;&gt;</font><font color="#ff0000" size="2">&amp;nbsp;</font><font size="2">Reverse Lookup by Invoice Number:</font><font color="#ff0000" size="2">&amp;nbsp;</font><font color="#0000ff" size="2">&lt;/</font><font color="#a31515" size="2">td</font><font color="#0000ff" size="2">&gt;</font></p> <p><font color="#0000ff" size="2">&nbsp;I have no class attached.&nbsp; However, there is a class attached to the parent outer td:</font></p> <font color="#0000ff"></font><font color="#0000ff" size="2"><font color="#0000ff" size="2"> <p>&lt;</font><font color="#a31515" size="2">td</font><font color="#000000" size="2"> </font><font color="#ff0000" size="2">class</font><font color="#0000ff" size="2">=&quot;trContent&quot;</font><font color="#000000" size="2"> </font><font color="#ff0000" size="2">style</font><font color="#0000ff" size="2">=&quot;width: 620px;&quot;&gt;</font></p> <p><font color="#0000ff" size="2">What I mean by parent outer td is:&nbsp; &lt;table&gt;&lt;tr&gt;&lt;td class=&quot;blah&quot;&gt;&lt;table&gt;&lt;tr&gt;&lt;td&gt;Reverse Lookup....&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</font></p> <p><font color="#0000ff" size="2">The trContent is defined as</font></p> <font color="#a31515" size="2"> <p>.trContent</p> </font><font size="2"> <p>{</p> </font><font color="#ff0000" size="2">background-color</font><font size="2">:</font><font color="#0000ff" size="2">#e1e1e1</font><font size="2">;</font></font><font size="2"> <p></font><font color="#ff0000" size="2">font-family</font><font size="2">:</font><font color="#0000ff" size="2">Verdana</font><font size="2">;</p> </font><font color="#ff0000" size="2">font-size</font><font size="2">:</font><font color="#0000ff" size="2">small</font><font size="2">;</font><font size="2"> <p></font><font color="#ff0000" size="2">font-weight</font><font size="2">:</font><font color="#0000ff" size="2">normal</font><font size="2">;</p> </font><font color="#ff0000" size="2">padding</font><font size="2">:</font><font color="#0000ff" size="2">1px</font><font size="2">;</font><font size="2"> <p>}</p> <p></font>&nbsp;This style for the font is applied to the text, &quot;Reverse Lookup by Invoice Number&quot; only on the second and so forth page loads, never on the first in IE 7 on my local machine running in either IIS&nbsp;5.1 in th .net Development Server but the style is always applied on first load on a remote server on the network in IIS 6</p> <p><font color="#0000ff" size="2">Of course, this is a simplisitic explamation of what is happening. So I think what may be happening is on the first load, the page is showing correctly and on the second&nbsp; and each additional load it is picking up an already used style from someplace else which technicaly it should not be doing.&nbsp; However, this is an odd explamation, perhaps not even correct and if it is the reason, it doesn't explaim the odd behaivor of why it works as I expect it to on a different server in IIS 6.&nbsp; Working in Firefox and not IE is a different issue as you know broswers implement things differently, I just would expect some consistensity between IIS 6 and so forth in the same browser.</font></p> <p><font color="#0000ff" size="2">I really dont know, Im happy that its working where its suppose to (in IIS 6) but I always just like to know the &quot;why&quot; to it.</font></p> <p><font color="#0000ff" size="2">Thanks!</font></p> <p><font color="#0000ff" size="2">John</p> </font><font size="2"></font> <p><font size="2">&nbsp;</p> </font> <p>&nbsp;</p> <p>&nbsp;</p> 2007-11-09T18:51:35-05:001999880http://forums.asp.net/p/1180199/1999880.aspx/1?Re+CSS+not+applied+on+first+loadRe: CSS not applied on first load <p>Is it possible that when you first load the page the Web Dev Server does not receive a compiled version of the Style code or maybe it isn't being compiled just in time?</p> <p>&nbsp;I have the cache problem with the browser all the time but have never seen this.&nbsp; Since you are adding styles in through code and the deployed solution works I have to wonder about the Web Development server.</p> 2007-11-10T19:27:36-05:002001859http://forums.asp.net/p/1180199/2001859.aspx/1?Re+CSS+not+applied+on+first+loadRe: CSS not applied on first load <p>Your guess is as good as mine, it has to be something with the Web Development Server</p> 2007-11-12T14:51:24-05:002002381http://forums.asp.net/p/1180199/2002381.aspx/1?Re+CSS+not+applied+on+first+loadRe: CSS not applied on first load <p>Any chance you can make this site live, so we can take a look at this weird behavior ourselves?&nbsp;</p> 2007-11-12T20:10:19-05:002002406http://forums.asp.net/p/1180199/2002406.aspx/1?Re+CSS+not+applied+on+first+loadRe: CSS not applied on first load Unfortunenly I cant make it live since it is an internal intranet.&nbsp; However, even if I could publish it live on our server external, it would show perfectly fine as the problem is on my local computer not our production web server. 2007-11-12T20:21:00-05:002115790http://forums.asp.net/p/1180199/2115790.aspx/1?Re+CSS+not+applied+on+first+loadRe: CSS not applied on first load <p>Hello, did you every find the solution to this problem?<br> I have the same problem. <br> Except I'm getting the same results on both the Development Server (VS 2005 Development IIS) and my Production (IIS 6.0) server. Seems to affect IE7 and not Firefox.</p> <p>Mine is a big project on a corporate site behind a login so I can't get an example for you.<br> <br> It is weird, I load the page the first time and use debugbar to look at the dom and the css files loaded.<br> The styles are all there in the html but not displayed on the page.<br> <br> I did notice that the styles are inserted in the body of the page and not in the header would this be causing the problem?<br> e.g. <br> &lt;SPAN id=QuoteTrackerStyleSheetHolder style=&quot;DISPLAY: none&quot;&gt;&lt;LINK href=&quot;/Grid/Skins/Default/Styles.css&quot; type=text/css rel=stylesheet&gt;&lt;/SPAN&gt;<br> <br> The problem happens on the production server until the css file is cached. (e.g. the first time you load the page after clearing the cache the styles are not applied)<br> It happens on the VS2005 Development Server too but because I'm in debug mode I see it a lot more because the css files are not cached between builds.</p> <p>Other things to note.<br> The css is the skin style for a third party control &quot;Telerik Radgrid&quot; and it's on a usercontrol that is being loaded onto the page via AJAX.<br> <br> </p> 2008-01-17T15:42:25-05:002118187http://forums.asp.net/p/1180199/2118187.aspx/1?Re+CSS+not+applied+on+first+loadRe: CSS not applied on first load <p>Your styles are inserted in the body of the page?!?! </p> <p>That could definitely be the problem, externally linked stylesheets should always be in the HEAD of your document. You can get away with placing embedded Style blocks within your markup, but having externally linked style sheets within your document may have some weird side effects. </p> <p>As I understand the Externally linked style sheets are loaded into the web browser first (since they're in the head), then applied to the document markup as it's being rendered / loaded. If the browser were to hit an externally linked stylesheet reference within the document it would have to stop loading the page, then reload the whole page again to have the styles applied, but it doesn't, instead it just keeps rendering the page without applying the StyleSheet. </p> <p>If you wanted to load stylesheets from within your document's markup you may want to look into using JavaScript to manipulate the StyleSheets or defining a ContentPlaceHolder in the head of your document for loading / unloading StyleSheets.</p> If you want to learn more about how StyleSheets and Styles are applied in the Browser, then check out this video: <a href="http://video.yahoo.com/video/play?vid=cccd4aa02a3993ab06e56af731346f78.996002"> An Inconvenient API: The Theory of the DOM</a> 2008-01-18T14:15:17-05:002122475http://forums.asp.net/p/1180199/2122475.aspx/1?Re+CSS+not+applied+on+first+loadRe: CSS not applied on first load <p>I never found a solution to my problem but what <a href="http://forums.asp.net/members/Adam.Kahtava.aspx"> <font color="#034efa">Adam.Kahtava</font></a>&nbsp; says may help as a solution for yours.&nbsp; Mine is just an annoynace as it only happens in my local test environment, not in production.&nbsp; Good luck!</p> 2008-01-21T15:04:53-05:002140829http://forums.asp.net/p/1180199/2140829.aspx/1?Re+CSS+not+applied+on+first+loadRe: CSS not applied on first load <p>Hi there !</p> <p>I had the very same &quot;problem&quot; but solved it.</p> <p>My call for the css class was in the head as it should, <br> but as my site was an ASP site with a pretty heavy query&nbsp;above in the code I found that this made the site&nbsp;just a litte to loaded when loading the page the first time.<br> With a refresh directlyu after the first load the page loads faster due to cash and by that the css got loaded.<br> <br> The solution was to move the call for css even before the head and&nbsp;query, after that&nbsp;it worka fine !&nbsp; [:D]</p> 2008-01-29T21:07:01-05:002154132http://forums.asp.net/p/1180199/2154132.aspx/1?Re+CSS+not+applied+on+first+loadRe: CSS not applied on first load <p>This may not be your issue since it's not isolated to Cassini, but I thought it may help others reading this thread. I ran into a similar issue while debugging and this article explained it perfectly.</p> <p>&nbsp;</p> <p><a href="http://weblogs.asp.net/scottgu/archive/2006/01/31/437027.aspx">http://weblogs.asp.net/scottgu/archive/2006/01/31/437027.aspx</a></p> 2008-02-05T12:58:41-05:004843846http://forums.asp.net/p/1180199/4843846.aspx/1?Re+CSS+not+applied+on+first+loadRe: CSS not applied on first load <p>This might help someone.</p> <p><strong>We had a&nbsp;<em>similar</em>&nbsp;problem:</strong>&nbsp;After a complete site re-design we noticed that in Firefox and IE, the first time you show up to the page the CSS styles were not being applied. However firebug showed that they were downloaded, also we had no errors. However upon Refresh the styles were applied and rendered properly.</p> <p><strong>The Solution:&nbsp;</strong>Even though the site re-design was completely new, out of habit our file structure and naming was consistant. Therefore being our NEW style sheet code was completely different but had the exact same file name and folder location as the OLD site.... the browser was trying to use the OLD cached copy of the CSS on first load, however on refresh is forced the use of the newest one.<br> <br> <strong>The Result:</strong>&nbsp;We changed the new css styles name, and everything is fixed. This was important to do because we have return visitors that surely were getting the same problem... and most people are hmmmm &quot;clever&quot; enough to hit refresh when the site loads weird, they just go away.</p> 2012-02-21T20:42:01-05:00