admin管理员组

文章数量:1312646

I have asp 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?

I have asp 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?

Share Improve this question edited Jun 23, 2011 at 15:24 Muhammad Akhtar 52.2k37 gold badges139 silver badges191 bronze badges asked Nov 26, 2009 at 9:18 Arsen MkrtchyanArsen Mkrtchyan 50.8k33 gold badges154 silver badges187 bronze badges 1
  • have you tried my solution? it will defintly work. – Muhammad Akhtar Commented Nov 26, 2009 at 9:36
Add a ment  | 

4 Answers 4

Reset to default 7

EDITED:

you always have the option of doing something like this:

<script type="text/javascript" language="javascript" src="<%= ResolveClientUrl("~/JScripts/JScripts.js") %>" />

you could try ResolveUrl this like...

Page.ClientScript.RegisterClientScriptInclude("JScripts", ResolveUrl("~/JScripts/JScripts.js"));

Have you considered specifying path from root?

src="/JScrips/JScripts.js"

How about:

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

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

本文标签: javascriptRelative script path in usercontrolStack Overflow