+1-888-365-2779
Try Now
More in this section

Forums / General Discussions / Including relative path

Including relative path

4 posts, 1 answered
  1. Martin
    Martin avatar
    6 posts
    Registered:
    14 Sep 2012
    30 Sep 2012
    Link to this post
    When you create a new page you can include header links to css and js.  I have created a folder callled js that exists at the same level as App_Data. I wish to reference a file within the page header at this level but am unsure how the relative path should appear?

    <script type="text/javascript" src="/js/myJavascriptFile.js"></script>
    <script type="text/javascript" src=" ~/js/myJavascriptFile.js"></script>
  2. Steve
    Steve avatar
    3037 posts
    Registered:
    03 Dec 2008
    30 Sep 2012
    Link to this post
    The first one is what you want, the slash at the start denotes "Start at the web root".  The second wont work at all as the "~" denoates an asp.net relative link, but that's resolved in the asp.net controls serverside, it's not a browser thing.  So the only what to resolve a ~ is to put runat="server" in the markup, but in this case if you do that it'll try and run the SCRIPT serverside and tank on you :)

    ...so use the first option :)

    Steve
    Answered
  3. Martin
    Martin avatar
    6 posts
    Registered:
    14 Sep 2012
    30 Sep 2012
    Link to this post
    Thank you Steve for your full answer
  4. MB
    MB avatar
    302 posts
    Registered:
    09 Jan 2005
    30 Sep 2012
    Link to this post
    @Steve

    Unless (of course) you were to override the main Render() event and process <script> tags. Not that I think it's a good idea, but I guess it's possible to do.
4 posts, 1 answered