0

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?

2 Answers 2

6

Your 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>
Sign up to request clarification or add additional context in comments.

Comments

0

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>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.