3

I found some old code which I'm not sure I understand completely. The folowing is an .aspx page containing only JavaScript:

<%@ Page Language="C#" EnableSessionState="True" CodePage="65001" uiculture="auto" %>

<%
Response.ContentType = "text/plain";
%>


var csBackgroundColor;

function testfx() {
    csBackgroundColor.setAttribute('disabled', 'disabled');
}

and it was referenced like this:

<script type="text/javascript" src="filename.js.aspx"></script>

I'm wondering why it wasn't just marked as completely a JavaScript file? Was it done this way so you could include code blocks? With the file this way, I don't even get IntelliSense.

2
  • 3
    That's the only content of the file? Commented Jun 27, 2012 at 0:41
  • 2
    +1 @ClaudioRedi would like to see if there is more server-side processing... Commented Jun 27, 2012 at 0:42

2 Answers 2

5

First time I see something like that but you're right, the reason behind this is to make the file to be processed by the asp.net engine and run it as any other aspx page, giving him the chance to use server side code to build the js file.

If that's all the code in the file, it seems the only objetive was to set the character encoding (CodePage="65001" and the content type (Response.ContentType="text/plain"). It wouldn't make a lot of sense as you can imagine.

Sign up to request clarification or add additional context in comments.

Comments

3

<hack>To get intellisense you could wrap the code in <script> ... </script> blocks and remove them before saving.</hack>

This was probably created by a developer that didn't want to, couldn't, or didn't have the time to write object oriented JavaScript. Encapsulating the logic and configuring through a configuration object would allow you to de-couple the code from external variable dependencies, (e.g. var foo = <%= SomeServerSideVariable %>).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.