views:

55

answers:

2

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?

+2  A: 

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.

Jay
This seems to have fixed it Jay. I don't know why though... maybe it's a visual studio debugger thing?
WOPR
Hey WOPR, it sounds like there was something else at play here, as setting an alert would not have fixed the problem, rather just let you know that the file itself was being loaded. I'd say some strange caching was the cause of this (especially if you were using IE, which has horrific javascript caching which you have to clear manually)
Jay
yup. I can remove the alert and it still works now.IE>>Trash. Install Chrome.
WOPR
Yep, that's fixed. Thanks again for your help.
WOPR
Good to hear, if you're looking at changing browsers and you're doing a lot of web development, take a look at Firefox with FireBug installed. It will help you clear up most problems like this in a matter of seconds. Though outside of web development I'd choose Chrome over Firefox personally.
Jay
A: 

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

hallie
The file is in the same folder as the css file. The css file gets processed properly so I presume it's correct?
WOPR
Just tried it. No joy.
WOPR