收录日期:2021/01/23 18:25:57 时间:2010-03-31 05:17:44 标签:asp.net,javascript

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?

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.

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