admin管理员组文章数量:1433520
I try to make Folder for things in my ASP.Net Application (e.g. all with Finance in /Finance).
No I bind an JavaScript in the MainPage:
<script type="text/javascript" src="Helper/jquery-1.3.2.min.js"></script>
But when I now open ~/Finance/Payment.aspx I get an JavaScript Error with "Path ~/Finance/Helper/jquery..." not found.
What to do?
I try to make Folder for things in my ASP.Net Application (e.g. all with Finance in /Finance).
No I bind an JavaScript in the MainPage:
<script type="text/javascript" src="Helper/jquery-1.3.2.min.js"></script>
But when I now open ~/Finance/Payment.aspx I get an JavaScript Error with "Path ~/Finance/Helper/jquery..." not found.
What to do?
Share Improve this question asked Nov 27, 2009 at 15:01 PassionateDeveloperPassionateDeveloper 15.2k35 gold badges111 silver badges190 bronze badges2 Answers
Reset to default 6Your path Helper/jquery-1.3.2.min.js
is a relative path. So when you go into /Finance
the browser is looking for jQuery in /Finance/Helper/jquery-1.3.2.min.js
.
A simple way around this is to use absolute paths
<script type="text/javascript" src="/Helper/jquery-1.3.2.min.js"></script>
Or you can use a ScriptManager which allows you to use the tilde
<asp:ScriptManager ID="ScriptManager1" runat="server">
<Scripts>
<asp:ScriptReference Path="~/Helper/jquery-1.3.2.min.js" />
</Scripts>
</asp:ScriptManager>
As a last resort if you have issues with the ScriptManager you can also do this
<script type="text/javascript"
src="<%= Page.ResolveClientUrl("~/Helper/jquery-1.3.2.min.js") %>">
</script>
You could always use ResolveClientUrl in the script src attribute (you'll need to make the path to your JavaScript file an app root relative path with the "~/"):
<script type="text/javascript" src="<%= ResolveClientUrl("~/Helper/jquery-1.3.2.min.js") %>"></script>
本文标签: ASPNet Dynamic JavaScript pathsrcStack Overflow
版权声明:本文标题:ASP.Net: Dynamic JavaScript pathsrc - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745442886a2658526.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论