Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

App_Themes and App_Browsers. Excluding CSS file depending on browser

Posted on 2009-04-06
4
Medium Priority
?
1,259 Views
Last Modified: 2013-11-07
Hi,

In my ASP.NET application I am using themes. When I went to validate I came across various errors to do with non-standard CSS. For example, I was using IE's zoom and _background-image and _height.

To get around this I placed IE specific CSS "Hacks" in a separate CSS file and was hoping to be able to explicitly state which CSS file the Theme should use in code behind.

Is this possible?

Also, it appears that the Theme is recursively adding references to all CSS files in the theme folder. Is it possible to avoid this?

Many thanks,

Tomás
0
Comment
Question by:mausy
  • 2
  • 2
4 Comments
 
LVL 4

Expert Comment

by:kruegerste
ID: 24096641
These "errors", are they preventing you from successfully building your application?  I use many IE specific CSS in my themes, and yes they display an error, but it doesn't stop the build process or affect anything. I just ignore them and everything is fine.  

If for some reason it does make your build fail, which I have never seen, just close the theme files when building and they won't be displayed.  VS quirk I think.
0
 
LVL 1

Author Comment

by:mausy
ID: 24097192
Hi kruegerste,

no, they don't stop be building my application. However, I want my web app's CSS to validate successfully via the CSS Validator at http://jigsaw.w3.org/css-validator/ and in order for it to validate I cannot have any of the aforementioned properties like zoom etc. To that end I want to exclude the CSS file in which I have included these "IE hacks". However, .NET seems to recursively add references to all CSS files under the App_Themes\[Theme] folder...

I hope I have explained myself well enough...

T
0
 
LVL 4

Accepted Solution

by:
kruegerste earned 1500 total points
ID: 24097306
"To get around this I placed IE specific CSS "Hacks" in a separate CSS file and was hoping to be able to explicitly state which CSS file the Theme should use in code behind. "

In the Pre-Render method of the code-behind, you can set the Theme as such:

Private Sub TripFile_PreInit(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreInit
        'Declare current Theme to Page
        Dim AppTheme As String
        AppTheme = Application.Item("g_Theme").ToString
        Page.Theme = AppTheme
 End Sub

In this instance, I save the theme in the web.config and create it as an application variable in the global.asax. But of course, you can determine which theme to use however you like.


"Also, it appears that the Theme is recursively adding references to all CSS files in the theme folder. Is it possible to avoid this?"

No, you can't remove a css file from the Themes directory if that theme is selected as current.  Your only option is to somehow create a separate styles directory outside of the app_themes folder and reference them from there.  This would be quite easy if these "hacks" are the same, regardless of theme.  
0
 
LVL 1

Author Closing Comment

by:mausy
ID: 31567125
Thanks kruegerste. That'll do the trick.

Cheers!
0

Featured Post

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
This video teaches viewers how to create their own website using cPanel and Wordpress. Tutorial walks users through how to set up their own domain name from tools like Domain Registrar, Hosting Account, and Wordpress. More specifically, the order in…
Learn how to set-up custom confirmation messages to users who complete your Wufoo form. Include inputs from fields in your form, webpage redirects, and more with Wufoo’s confirmation options.

783 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question