Computers & ProgrammingASPBackend Development

Basic Syntax for ASP

So what does the basic structure and syntax of an ASP page look like? An ASP file appears to be very similar to that of a typical HTML file, with one exception. While an HTML file normally contains HTML elements, an ASP file will also contain server-side scripts, which are normally encapsulated by two special delimiters, <% and %>.

Server-side scripts are executed on the server, and not on the client browser. They can contain statements, procedures, and/or operators that are valid for the scripting language you define within your ASP page. If you do not declare a scripting language, VBScript is used as the default language.

ASP includes support for both VBScript and JScript. JScript is actually the same as JavaScript but with a different name. If you want to use another scripting language, you will need to install the appropriate scripting software on the web server to support them.

VBScript Example

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

JavaScript Example

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

The two examples above seem to have identical code. The only difference is that the second example has a declaration on line 1. To set JavaScript (or any other language) as the default scripting language for a particular page, you must insert a language specification at the top of the page before any other HTML code. You should also note that JavaScript is case-sensitive. However, VBScript is not.

Another way to introduce server-side VBScript is to use the <script> element. To instruct the web server to treat the code as server-side rather than client-side, you need to ensure that the runat attribute is included.

<!DOCTYPE html>
<html>
<head>
    <title>Hello World!</title>
</head>
<body>
 <script language="vbscript" runat="server">
  response.write("Hello World!")
 </script>
</body>
</html>

It is also possible to mix JavaScript and VBScript server-side blocks within the same page, as well as the client-side script. Please note that client-side VBScripts will only run within a Microsoft Internet Explorer browser. For this reason, it is common to not implement client-side scripting using VBScript.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top