Arsen Mkrtchyan
Arsen Mkrtchyan

Reputation: 50752

Relative script path in usercontrol

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 folder 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?

Upvotes: 2

Views: 1577

Answers (4)

Veli Gebrev
Veli Gebrev

Reputation: 2521

EDITED:

you always have the option of doing something like this:

<script type="text/javascript" language="javascript" src="<%= ResolveClientUrl("~/JScripts/JScripts.js") %>" />

Upvotes: 7

Muhammad Akhtar
Muhammad Akhtar

Reputation: 52241

you could try ResolveUrl this like...

Page.ClientScript.RegisterClientScriptInclude("JScripts", ResolveUrl("~/JScripts/JScripts.js"));

Upvotes: 3

David Hedlund
David Hedlund

Reputation: 129802

Have you considered specifying path from root?

src="/JScrips/JScripts.js"

Upvotes: 2

marcgg
marcgg

Reputation: 66465

How about:

<script type="text/javascript" language="javascript" src="/JScripts/JScripts.js"/>

(use the absolute path from the root of your app)

Upvotes: 1

Related Questions