Question

I'm using ASP.Net Dynamic Data. I have the following line in my site.master page.

<script src="../Scripts/jquery-ui-1.8.20.custom.min.js" type="text/javascript"></script>

The path is correct and file exists. But when I load the page I can see in the Net panel of firebug that it cant find the file. Error message is "404 Not Found"

Was it helpful?

Solution

I dont trust your url :)

use :

<script src='ResolveUrl("~/Scripts/jquery-ui-1.8.20.custom.min.js")' type="text/javascript"></script>

also , please verify - you load the jQuery.js BEFORE you load this line.

OTHER TIPS

Approach - 1

You should modify the code like as mentioned in below ways...

  1. ~/Scripts/jquery-ui-1.8.20.custom.min.js
  2. "<%#ResolveUrl("~/Scripts/jquery-ui-1.8.20.custom.min.js")%>"

in the first case replace the .. with ~

Approach - 2

Alternatively, Right click the Page and select View Source. click the link of your Script file and check if it navigating to your actual Script file? Otherwise make the necessary changes as mentioned above.

When you use ../ at the beginning of a url, it is the browser's current url that is taken as the base. So that url will only work when you are at exactly one directory level down from the site root, like this:

http://myserver:myport/myvirtualdir/somedir/somepage.aspx

Or this:

http://myserver:myport/myvirtualdir/somedir/ (using a default page or view)

Then, the browser will load the following script:

http://myserver:myport/myvirtualdir/Scripts/jquery-ui-1.8.20.custom.min.js

But if you are at any other directory depth, the browser will use the wrong url for the script. Like if you are at the root default page:

http://myserver:myport/myvirtualdir/Default.aspx

Then the browser will try to load the script from the wrong directory:

http://myserver:myport/Scripts/jquery-ui-1.8.20.custom.min.js

That is why you need to resolve the url on the serverside, like a couple of people have already said here. That will provide the browser with a working url for your script. There's a difference between file paths and urls.

The fact that you are getting a 404 means that the url that the browser is trying to reach is simply not correct, from the browser's point of view, which is in fact the only point of view that is valid, even if you, the developer, is convinced that you are doing it right...

<script src="<%#ResolveUrl("~/Scripts/jquery-ui-1.8.20.custom.min.js")%>"></script>

As Royi mentioned make sure you have the jquery.js before you have your jquery-ui.js

<script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
<script src="Scripts/jquery-ui-1.8.20.custom.min.js" type="text/javascript"></script>

Here is a tip. open site.Master designer then drag and drop the .js file from the Solution Explorer into the designer. It would create the path for you.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top