[英]Relative script path in usercontrol
I have asp.net usercontrol that is including some js script like this 我有asp.net usercontrol,包括一些像这样的js脚本
<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. 问题是,当我在某些页面中使用此usercontrol时,它可以正常工作,但是当在另一个文件夹结构中使用某些页面时,它会因找不到文件的异常消息而失败。 Changing js path to 将js路径更改为
~/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) (使用应用程序根目录的绝对路径)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.