ASP syntax



In our ASP tutorials, hidden ASP source code is provided for each example. This will make it easier for you to understand how they work.


Writing output to the browser

ASP files usually contain HTML tags, just like HTML files. However, ASP files can also contain server scripts, which are surrounded by the delimiters <% and %>.

Server scriptExecuted on the server, it can contain legal expressions, statements, procedures or operators in the scripting language you choose.

response.write command

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

Instance

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

Run Instance»

Click "Run Instance" Button to view online examples

There is also a shorthand method for the response.write command. The following example also sends a piece of text to the browser: "Hello World":

Instance

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

Run Instance»

Click "Run Instance" " button to view online examples



#Using VBScript in ASP

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

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

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


Using JavaScript in ASP

If you need to set JavaScript as the default scripting language for a specific page, you must insert a line of language description at the top of the page:

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

Note: Unlike VBScript, JavaScript is case-sensitive! You must write your ASP code using different uppercase and lowercase letters as required by JavaScript.


Other scripting languages

ASP's integration with VBScript and JScript (JScript is Microsoft's JavaScript implementation) is native. If you want to write scripts in another language, such as PERL, REXX, or Python, you must install the corresponding scripting engine.


Examples

More examples

Add some HTML tags to the text