开发者

Cannot call external javascript function from SITE.MASTER

开发者 https://www.devze.com 2022-12-25 18:24 出处:网络
I have a Site.Master in my ASP.NET project which defines a HEAD section as follows <head runat=\"server\">

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();

开发者_StackOverflow
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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号