1

I have in my C#, .NET 3.5 (VS2008) web project's App_Themes directory a theme directory called Theme1. In that directory I have various other directories. Some of theme contain .css files and some contain .js files. In my web pages, which use this theme, the appropriate link tags are rendered, in the HTML, for the .css files, but not the .js files. What am I doing wrong, or do I simply have to share all my .js files across all themes from a centralised directory?

2
  • Can you post an example <script> reference that isn't working correctly? Commented Aug 13, 2010 at 9:57
  • It's not the reference that isn't working, it's that ASP.NET doesn't render a script tag at all for the .js files inside the particular theme's directory. Commented Aug 13, 2010 at 10:00

1 Answer 1

4

If you place the JS files in your theme directory you can use the Page.Theme name to get the appropriate path for the current theme.

<script type="text/javascript" src="<%=ResolveUrl("~/App_Themes/" + Page.Theme + "/js/script.js") %>"></script>
Sign up to request clarification or add additional context in comments.

3 Comments

So, references to .js files are not include in the HTML by ASP.NET when they are placed inside theme directories?
That is correct. You must individually specify what to load.
This does make sense as you're likely to have site-wide and page-specific js

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.