0

I found that ResolveClientUrl() works as expected when JavaScript is embedded in ASPX page, however it doesn't resolve anything when external script is referenced in ASPX like this:

<script src="../Javascript/sessionManagement.js" type="text/javascript"></script>

Is there a way to make ResolveClientUrl() work in external JS files? I was expected that it would because this file IS included in ASPX page but this is not the case.

I found a rather ugly workaround - to include external JS file in ASPX page like this:

<script type="text/javascript" language="jscript">
    <!--#include file="../Javascript/sessionManagement.js"-->
</script>

It works (ResolveClientUrl() actually resolves path) but I've never seen external JS files referenced like that and am not sure this is the way to go.

1
  • 1
    Your .js files are not processed as .aspx pages, you can't run inline C# or VB code on them. Instead, run it directly on the .aspx page and then access that variable from your JS, or pass it through a function. Commented Sep 26, 2014 at 14:47

1 Answer 1

2
<script type="text/javascript">
var myUrl = '<%= ResolveClientUrl("MyURL") %>';
</script>

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

and in your sessionManagement.js, you can simply use the myUrl variable above

Sign up to request clarification or add additional context in comments.

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.