简体   繁体   中英

Relative script path in usercontrol

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?

EDITED:

you always have the option of doing something like this:

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

你可以尝试ResolveUrl这样......

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

您是否考虑过从根指定路径?

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM