When a web browser wants a web page it issues an HTTP GET to the server for the html file, or in this case, your aspx file. The web server, in this case IIS, knows that the file that the client requested is an ASP.NET web form by identifying the .aspx file extension. It uses that as a cue that it needs to execute the dynamic content in your web form, and send the output to the TCP stream.
When the client browser receives your HTML, it parses it, and makes a list of all external resources in the HTML such as CSS, images, and your javascript. It then issues a separate HTTP GET for each of those resources. Once it has received them all it assembles and renders the page to the user.
In that previous step the browser made a request for your .js file. The server received the request and happily delivered the javascript to your browser. Since the file extension is .js, not .aspx it didn't know that you wanted it to parse the javascript and look for your codebehind reference. It just delivered the goods.
You have three options.
1. Just embed the javascript in the html file like you did originally.
2. Rename the standalone javascript file to a .aspx extension and in the .aspx add a
ContentType @Page directive[
^] to text/javascript. In your HTML, link to the .aspx file.
<script src="scripts/test.aspx" type="text/javascript"></script>
IIS will now parse and compile your javascript document, correctly rendering your codebehind; since the MIME content type is correctly set, the browser will treat it as javascript, even though it has a .aspx extension.
3. In the IIS configuration (or web.config) you can configure IIS so that it treats all .js files as web forms.
How nice, THREE options!