Calling js file from Master page

  • Thread starter Thread starter neilr
  • Start date Start date
N

neilr

We are trying to use a suggestion from an old post but cannot make it
work. We have a file (CommonFunctions.js) of jave functions in a
directory on our site and would like to be able to call the functions
from any page on the site by linking to it in the header section of a
master page. We have tried various ways but this is the current header
block in our base-level master page:

<head runat="server">
<title>Untitled Page</title>
<script type="text/javascript" src= "~/CommonFiles/JS/
CommonFunctions.js") "></script>
</head>

Sadly, it does not work - we get an " XXX.js is undefined" error on
every opage that has a js function

Can anyone help?
 
Remove the <script> tag. Then put this in the Page_Load event:

Page.ClientScript.RegisterClientScriptInclude("somescript",
ResolveUrl("~/CommonFiles/js/CommonFunctions.js"));


--
Gregory A. Beamer
MVP, MCP: +I, SE, SD, DBA

Subscribe to my blog
http://feeds.feedburner.com/GregoryBeamer#

or just read it:
http://feeds.feedburner.com/GregoryBeamer

********************************************
| Think outside the box! |
********************************************
 
Back
Top