Javascript file not linking in aspx file

Discussion in 'ASP.NET / ASP.NET Core' started by njones, Jun 19, 2011.

  1. Hi,

    I have an aspx page in which I'm trying to link to javascript file stored in a separate folder under my web application. But it doesn't seem to work. The script is included with the following statement in the aspx file.

    <asp:Content ID="scripts" runat="server" ContentPlaceHolderID="scriptsdiv">
    <script src="~/Scripts/metterSearch.js" language="javascript" type="text/javascript"/>
    </asp:Content>

    The asp:Content block is placed at the very bottom of the page, i.e. just before the </form> tag. I tried giving the src as "Scripts/metterSearch.js", "/Scripts/metterSearch.js", and the full pathname too, but none of them work. However,the script works if I put the text of the script directly in the asp:Content block.

    Does anyone have any idea why I'm not able to get this to work?

    Thanks,
    Naveen
     
  2. The script file is linking now.

    I solved it by first moving the file to directly under the root folder and running the application. Once this was done, I moved the file back to the original Scripts folder and changed the pathname to Scripts/metterSearch.js. It works now!. No idea why it didn't work the first time.

    Thanks,
    Naveen
     
  3. Good job ;-)
     

Share This Page