Including Javascript code
-
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 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
Just Remove runat="server" code Best Regard Pathan
GOD HELP THOSE WHO HELP THEMSELVES
-
Just Remove runat="server" code Best Regard Pathan
GOD HELP THOSE WHO HELP THEMSELVES
"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.
-
"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.
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");