views:

186

answers:

4

Hi, I have asp.net usercontrol that is including some js script like this

<script type="text/javascript" language="javascript" src="../JScripts/JScripts.js"/>

The problem is that when I am using this usercontrol in some pages, it works correctly, but when using some pages in another folder structure, it fails with the file not found exception message. Changing js path to

~/JScripts/JScripts.js

doesn't help. is there any way to solve this problem decoratively?

+1  A: 

How about:

<script type="text/javascript" language="javascript" src="/JScripts/JScripts.js"/>

(use the absolute path from the root of your app)

marcgg
+3  A: 

Have you considered specifying path from root?

src="/JScrips/JScripts.js"
David Hedlund
doesn't work :(
ArsenMkrt
This would work if you ensure you use the full relative path from your root - we don't know what it is, but for example "/MyApp/Resources/JScripts/JScrupts.js".
Sohnee
Also, you'd need to spell JScripts correctly, not like I did in my comment.
Sohnee
Thanks @d and @Sohnee it works
ArsenMkrt
You shouldn't hardcode the path like that. If you want absolute paths use <%= ResolveUrl("~/JScripts/JScripts.js") %> instead.
pbz
+3  A: 

you could try ResolveUrl this like...

Page.ClientScript.RegisterClientScriptInclude("JScripts", ResolveUrl("~/JScripts/JScripts.js"));
Muhammad Akhtar
+5  A: 

EDITED:

you always have the option of doing something like this:

<script type="text/javascript" language="javascript" src="<%= ResolveClientUrl("~/JScripts/JScripts.js") %>" />
Veli
Or you could use ResolveUrl which would give you an absolute path relative to the application's root. Nothing wrong with ResolveClientUrl.
pbz