0

I am using asp.net 4 routing and im enjoying it so far. I have one problem only with my javascript files. I am using a masterpage to add my css and javascript. The css is working fine however the javascript is not.

My links from my masterpage look like this

  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="~/_styles/css/core.css" rel="stylesheet" type="text/css" />

<link href="~/_styles/css/facebox.css" rel="stylesheet" type="text/css" />
<script src="~/_styles/js/jquery-1.3.2.min.js" type="text/javascript"></script>
<script src="~/_styles/js/jquery.validate.js" type="text/javascript"></script>

<script src="~/_styles/js/facebox.js" type="text/javascript"></script>
<script src="~/_styles/js/corejs.js" type="text/javascript"></script>

Why does my css load correctly but the js doesnt?

4
  • Can you provide the directory structure as well? Are your js files in the _styles/js folder ? Commented Nov 14, 2010 at 7:58
  • Yes I have my my masterpage at the root including my pages. I have then created a folder called _styles which then has folders for css and js Commented Nov 14, 2010 at 8:00
  • If I look at the source of the page my links have changed to look like this <link href="../_styles/css/core.css" rel="stylesheet" type="text/css" /><link href="../_styles/css/facebox.css" rel="stylesheet" type="text/css" /> <script src="~/_styles/js/jquery-1.3.2.min.js" type="text/javascript"></script> <script src="~/_styles/js/jquery.validate.js" type="text/javascript"></script> <script src="~/_styles/js/facebox.js" type="text/javascript"></script> <script src="~/_styles/js/corejs.js" type="text/javascript"></script> Commented Nov 14, 2010 at 8:01
  • 2
    AFAIK ~/_styles only works for controls with runat=server. try changing the references to simply /_styles Commented Nov 14, 2010 at 8:07

3 Answers 3

3

This is question is bit old..but i faced same situation using ASP.NET 4.0 routing and referencing different js file or stylesheet when you move from different directory structure.. what i used to resolve is:

<script src='<%=ResolveClientUrl("~/js/fancybox/jquery.fancybox-1.3.4.js")%>' type="text/javascript"></script>

So key was using ResolveClientUrl

Hope this helps people in future.

Sign up to request clarification or add additional context in comments.

Comments

0

Please check and make sure when you adding the link for your script.You just type the <script src=" and Ctrl+Space then choose your file.If you can't find your project path,just try it to get in that path.Sometime,the file will not in that path when you may be copy & paste that file to your project path(not from your VS Project explorer).

Comments

0

you can use simply _styles/js and _styles/css.

Comments

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.