ASP Syntax

You cannot see the ASP source code by viewing the source code in the browser. You can only see the results output by the ASP file, which are just pure HTML. This is because the script has already been executed on the server before the results are sent back to the browser.

In our ASP tutorial, each example provides hidden ASP code. This makes it easier for you to understand how they work.

Example

Writing text with ASP
If generating text with ASP.
Adding HTML to text
If generating both HTML tags and plain text.

Basic ASP syntax rules

In most cases, ASP files contain HTML tags, similar to HTML files. However, ASP files can also containServer-side scripts, these scripts are separated by <% and %> Enclosed.

Server-side scriptsExecuted on the server, which can include valid expressions, statements, or operators.

Writing output to the browser

The response.write command is used to write output to the browser. The following example sends a text segment to the browser: "Hello World".

<html>
<body>
<%
response.write("Hello World!")
%>
</body>
</html>

There is also a shorthand method for the response.write command. The following example is equivalent to the previous one:

<html>
<body>
<%="Hello World!"%>
</body>
</html>

Using VBScript in ASP

You can use several scripting languages in ASP. However, the default scripting language is VBScript:

<html>
<body>
<%
response.write("Hello World!")
%>
</body>
</html>

The example above writes the text "Hello World!" to the body of the document.

Tip:If you need to learn more about VBScript, please study our VBScript Tutorial.

Using JavaScript in ASP

If you need to use JavaScript as the default script language for a specific page, you must insert a line of language setting at the top of the page:

<%@ language="javascript"%>
<html>
<body>
<%
Response.Write("Hello World!")
%>
</body>
</html>

Note:Unlike VBScript, JavaScript is case-sensitive. Therefore, you need to use different uppercase and lowercase letters according to the needs of JavaScript when writing ASP code.

Tip:If you need to learn more about JavaScript, please study our JavaScript Tutorial.

Other scripting languages

The cooperation between ASP and VBScript and JScript is native (JScript is Microsoft's implementation of JavaScript). If you need to use other languages to write scripts, such as PERL, REXX, or Python, you must install the corresponding script engine.

Important Matters:Since the script is executed on the server side, the browser displaying the ASP file does not need to support scripts.