Calling js file from Master page

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?
 
C

Cowboy \(Gregory A. Beamer\)

Remove the <script> tag. Then put this in the Page_Load event:

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,825
Latest member
VernonQuy6

Latest Threads

Top