Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Including Javascript code

Including Javascript code

Scheduled Pinned Locked Moved ASP.NET
javascripthelp
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Sam Heller
    wrote on last edited by
    #1

    I am trying to include a Javscript file in all of my pages using the following line, written into the section of my master page. For some reason I get the following error Parser Error Message: Cannot use 'javascript' because another language has been specified earlier in this page (or was implied from a CodeFile attribute). Any ideas how I can get around this as I need the runat tag and the ~ root symbol to find the file from all directories. Thanks

    I 1 Reply Last reply
    0
    • S Sam Heller

      I am trying to include a Javscript file in all of my pages using the following line, written into the section of my master page. For some reason I get the following error Parser Error Message: Cannot use 'javascript' because another language has been specified earlier in this page (or was implied from a CodeFile attribute). Any ideas how I can get around this as I need the runat tag and the ~ root symbol to find the file from all directories. Thanks

      I Offline
      I Offline
      Imran Khan Pathan
      wrote on last edited by
      #2

      Just Remove runat="server" code Best Regard Pathan

      GOD HELP THOSE WHO HELP THEMSELVES

      S 1 Reply Last reply
      0
      • I Imran Khan Pathan

        Just Remove runat="server" code Best Regard Pathan

        GOD HELP THOSE WHO HELP THEMSELVES

        S Offline
        S Offline
        Sam Heller
        wrote on last edited by
        #3

        "as I need the runat tag and the ~ root symbol to find the file from all directories." Did I not make that bit obvious enough? Lose the runat tag and the ~ symbol means nothing a will never work. Sometimes pages are one folder level up sometimes two, sometimes three. Therefore I have to use the runat attribute.

        S 1 Reply Last reply
        0
        • S Sam Heller

          "as I need the runat tag and the ~ root symbol to find the file from all directories." Did I not make that bit obvious enough? Lose the runat tag and the ~ symbol means nothing a will never work. Sometimes pages are one folder level up sometimes two, sometimes three. Therefore I have to use the runat attribute.

          S Offline
          S Offline
          szukuro
          wrote on last edited by
          #4

          You're right that you need the runat="server" for the ~ symbol to work, however it will never work like you want it to, because then it will be treated as server-side script. So another approach is recommended. One idea would be to use full url paths, which could be constructed in the codebehind. Like:

          string webroot = Request.Url.ToString().Replace(Request.Path, String.Empty);
          Page.ClientScript.RegisterClientScriptInclude("mad", webroot + "/Javascript/MAD.js");

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups