1

I have a master page with the following lines inside my <head> tags.

<link href="Styles/Style.css" rel="stylesheet" type="text/css" />
<script src="Scripts/navmenu.js" type="text/javascript"></script>

When I navigate to a page that uses URL routing, the lines above generate the following HTML.

<link href="../../Styles/Style.css" rel="stylesheet" type="text/css" />
<script src="Scripts/navmenu.js" type="text/javascript"></script>

Based on the mapped URL, the stylesheet link is correct. How can I get the script link to also be correct?

P.S. I tried setting runat="server" in the script link but that just seems to confuse ASP.NET. The entire project fails to compile based on bogus errors reported in my JavaScript file. (The javascript file runs fine otherwise.)

3
  • Well, absolute URLs will only work in one place. For example, I couldn't test them on my development machine. Commented Apr 24, 2011 at 1:56
  • I'm really not following. If I use absolute URLs that refer to my web server, and I'm testing on my development machine, then I wouldn't be testing the files I'm developing. They'd be including the wrong files. (My development machine is a different computer than my web server.) Commented Apr 24, 2011 at 2:08
  • Sorry. Boy, I'd need to check that out. It's been my experience that "/" doesn't work on my dev machine. I'm not at my dev machine right now but will verify this next time I am. Commented Apr 24, 2011 at 3:40

1 Answer 1

1

It looks like the best answer is this:

<link href="Styles/Style.css" rel="stylesheet" type="text/css" />
<script src='<%= ResolveClientUrl("~/Scripts/navmenu.js") %>' type="text/javascript"></script>

Note that if I use the ResolveClientUrl() for the stylesheet <link> tag, it doesn't work. Apparently, there is special handing for this tag.

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

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.