开发者

How to give path from one sub directory to other subdirectory?

On root of application I have two folders: 1.Admin 2.JavaScript

My web page is in Admin folder and script file is in Javascript folder. How I should give path of script file in web page in Admin fold开发者_如何学JAVAer. I have tried these three ways but file is not found in brorser, please guide:

<script type="text/javascript" src="JavaScript/Common.js"></script>
<script type="text/javascript" src="../JavaScript/Common.js"></script>
<script type="text/javascript" src="~/JavaScript/Common.js"></script>

Eidt In Admin folder I have master page and in same folder I have content page. The error I am getting on client side is showign javascript as it is in Admin panel like "NetworkError: 404 Not Found - http://localhost:1532/MyProject/Admin/JavaScript/Common.js"


Leading slash replaces the entire pathname of the base URL.

<script type="text/javascript" src="/JavaScript/Common.js"></script>

By your edit, your project is no off the root as you suggested.

<script type="text/javascript" src="/MyProject/JavaScript/Common.js"></script>


You can use a relative path like you have in your second example, or you can use a direct path from the root:

<script type="text/javascript" src="/JavaScript/Common.js"></script>

Just make sure your path is accessible and that you've haven't typoed any of the directory names, etc. That's usually my problem when I have a file that's not loading properly.


Your second example looks correct, so you should check the case of the directories. Personally I like the following method, which would work in any of your files:

<script type="text/javascript" src="/JavaScript/Common.js"></script>

/ at the beginning of a string specifies the root, which is what it looks like you want.

Edit
From your update, it looks like you want
<script type="text/javascript" src="/MyProject/JavaScript/Common.js"></script>.

The root (/) specifies the slash right after the port.


Try this:

<script type="text/javascript" src="<%=ResolveUrl("~/JavaScript/Common.js")%>"></script>

The tilde(~) is the ASP.NET way to go to the root-directory. This works on server controls and with ResolveUrl.

If you are using a ScriptManager in your MasterPage do following:

Add the path to your javascript file(s) as ScriptReference to your ScriptManager/ToolkitScriptManager.

<asp:ScriptManager ID="ScriptManager1" runat="server">
    <Scripts>
       <asp:ScriptReference Path="~/JavaScript/Common.js" />
    </Scripts>
</asp:ScriptManager>

More informations: http://weblogs.asp.net/fmarguerie/archive/2004/05/05/avoiding-problems-with-relative-and-absolute-urls-in-asp-net.aspx

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜