0

In Site.Master page, I have references to a few CSS and JS files. When a page in a subfolder uses this master page, I can see that the css file's path gets correctly translated, by adding necessary ../ in front of it, but not for JS files which results in 404 errors when viewed in Chrome's debug window.

I tired using ~ with runat=server to force translation; didn't work; tried using Page.ResolveURL that gives no error message but seems to break the script and not sure how I can this to work.

In Site.Master:

<!-- Bootstrap Core CSS -->
<link href="assets/css/bootstrap.min.css" rel="stylesheet" />

This gets correctly displayed as the following for a .aspx page that is in a sub-folder:

<link href="../assets/css/bootstrap.min.css" rel="stylesheet" />

for JS files, none of the following works.

This one shows just as is for the same file in sub-folder:

<!-- Bootstrap Core JavaScript -->
<script src="assets/scripts/bootstrap.min.js"></script>

This one shows no 404 erro; a "/<sitename>/" gets prepended to path but script does not work (e.g. drop down menu does not drop)

<!-- Bootstrap Core JavaScript -->
<script src='<%= Page.ResolveUrl("~/assets/scripts/bootstrap.min.js") %>'></script>

And this one, I don't think I can do this!

<!-- Bootstrap Core JavaScript -->
<script runat="server" src="~/assets/scripts/bootstrap.min.js"></script>
mason
  • 31,774
  • 10
  • 77
  • 121
NoBullMan
  • 2,032
  • 5
  • 40
  • 93

1 Answers1

1

I found the answer here. The post offers a few options but what was listed as Edit2 of the answer was what worked for me:

<!-- jQuery -->
<script type="text/javascript" src='<%= Page.ResolveClientUrl("~/assets/scripts/jquery.js") %>' ></script>

<!-- Bootstrap Core JavaScript -->
<script type="text/javascript" src='<%= Page.ResolveClientUrl("~/assets/scripts/bootstrap.min.js") %>' ></script>
NoBullMan
  • 2,032
  • 5
  • 40
  • 93