Download presentation
Presentation is loading. Please wait.
Published byDarrell Skinner Modified over 9 years ago
1
Lecture Note 3: ASP Syntax
2
ASP Syntax ASP Syntax ASP Code is Browser-Independent. You cannot view the ASP source code by selecting "View source" in a browser, you will only see the output from the ASP file, which is plain HTML. This is because the scripts are executed on the server before the result is sent back to the browser. The Basic Syntax Rule The Basic Syntax Rule An ASP file normally contains HTML tags, just like an HTML file. However, an ASP file can also contain server scripts, surrounded by the delimiters. Server scripts are executed on the server, and can contain any expressions, statements, procedures, or operators valid for the scripting language you prefer to use.
3
Step 1: Step 1: –This tells the script interpreter that this script is written using JavaScript. The default for ASP is VBScript. The are script delimiters - they tell the interpreter that the code within them needs to be interpreted. Usually the code outside of the delimiters will be HTML or client side JavaScript.
4
Step 2: <% Option Explicit dim Qty, Price, Total Step 2: <% Option Explicit dim Qty, Price, Total –Option Explicit means that we have to dimension all of our variables before we can use them. This is a good idea because if we accidentally mis-spell something the interpreter will notice and give us a helpful error message - bugs like this are often the hardest to find, so it's good to try and avoid them if we can. Then we dimension our variables using dim - this allocates some memory for the computer to store values while our script is running. Qty = Request("Qty") Price = Request("Price") Qty = Request("Qty") Price = Request("Price") The values we entered in our form can be accessed using Request("FormVariableName"). In these two lines, we store these values in two ASP variables so that we can use them later.
5
Total = Qty * Price %> This is where we do the calculation.. We also close the script off by using %>, telling the interpreter that the next lines are HTML.
6
Step 3: Step 3: Simple calculator Simple calculator You entered. You entered. The Total amount is. The Total amount is. This is just straight HTML, but if you look carefully you'll find 2 bits of embedded ASP: and. This is telling the interpreter to substitute the value of those variables in at those points. (The = is important here - if you leave it out, you won't get anything substituted.) And there you have it, your first ASP script. This is just straight HTML, but if you look carefully you'll find 2 bits of embedded ASP: and. This is telling the interpreter to substitute the value of those variables in at those points. (The = is important here - if you leave it out, you won't get anything substituted.) And there you have it, your first ASP script.
7
The Response Object The Write method of the ASP Response Object is used to send content to the browser. For example, the following statement sends the text "Hello World" to the browser: The Response Object The Write method of the ASP Response Object is used to send content to the browser. For example, the following statement sends the text "Hello World" to the browser:
8
VBScript VBScript You may use different scripting languages in ASP files. However, the default scripting language is VBScript: The example above writes "Hello World!" into the body of the document.
9
JavaScript JavaScript To set JavaScript as the default scripting language for a particular page you must insert a language specification at the top of the page: Note: Unlike VBScript - JavaScript is case sensitive. You will have to write your ASP code with uppercase letters and lowercase letters when the language requires it. Note: Unlike VBScript - JavaScript is case sensitive. You will have to write your ASP code with uppercase letters and lowercase letters when the language requires it.
10
Examples How to write some text with ASP Examples How to write some text with ASP
11
Other Scripting Languages Other Scripting Languages ASP is shipped with VBScript and JScript (Microsoft's implementation of JavaScript). If you want to script in another language, like PERL, REXX, or Python, you will have to install script engines for them.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.