开发者

Relative script path in usercontrol

开发者 https://www.devze.com 2022-12-12 08:53 出处:网络
I have asp.net usercontrol that is including some js script like this <script type=\"text/javascript\" language=\"javascript\" src=\"../JScripts/JScripts.js\"/>

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 fol开发者_JAVA百科der 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") %>" />


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)

0

精彩评论

暂无评论...
验证码 换一张
取 消