WOPR
WOPR

Reputation: 5393

Cannot call external javascript function from SITE.MASTER

I have a Site.Master in my ASP.NET project which defines a HEAD section as follows

<head runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title id="MasterTitle">MyApp</title>
    <link rel="icon" href="Content/icon.ico" type="image/x-icon" />
    <link href="Content/mycss.css" rel="stylesheet" type="text/css" />
    <script src="Content/mycode.js" type="text/javascript"></script>
</head>

In the mycode.js file, I have a function called GetSels();

function GetSels()
{
//do stuff
}

If the GetSels function is defined in Site.Master, GetSels is callable. If it's in mycode.js, it's not.

Every code example I've seen seems to say this should work.

What am I doing wrong?

Upvotes: 0

Views: 2288

Answers (2)

Jay
Jay

Reputation: 4280

This should really work perfectly as I have done this multiple times myself.

Check that the code in your external javascript file runs correctly on page load, this is just to make sure that it is indeed being loaded correctly into your document. For example set an alert("It's loaded"); in your external .js file.

Upvotes: 2

hallie
hallie

Reputation: 2845

have you checked that your reference to mycode.js is correct? if your using a relative path try "~/Content/mycode.js" in your reference.

Upvotes: 0

Related Questions