ASP Syntax
ASP syntax
- An ASP file normally contains HTML tags,just like an HTML file.
- An ASP file also contains server scripts,surrounded by the delimiters <% and %>.
- Server scripts are executed on the server,and can contain any expressioons,statements,procedures, or operators valid for scripting language you prefer to use.
A simple example(1):
| <html> <body> <% Response.Write(“Good afternoon user!”)%> </body> </html> |
OUTPUT :
Good afternoon user!
Here, the Response.Write command is used to write output to a browser.
A simple example(2):
Adding some HTML to the text
| <html> <body> <% Response.Write(“<h2>You can use HTML tags to format the text!<h2>”) %> <% Response.Write(“<p style=’color:#0000ff’>This text is styled with the style attribute!</p>”) %> </body> </html> |
Viewing an ASP file
- One cannot view the ASP source code by selecting "View source" in a browser.
- The output is seen from the ASP file(plain HTML). This is because the scripts are executed on the server before the result is sent back to the browser.
Writing ASP
- The default scripting language is VBScript.
- One can use several Scripting languages in ASP like JavaScript.
- To set JavaScript as the default scripting language for a particular page one must insert a a language specification at the top of the page :
<%@language=”javascript”%>
<html>
<body>
…..
</body>
</html>
Variables in ASP
- A variable is used to store information.
- If a variable is declared outside a procedure it can be changed by any script in an ASP file.
- If a variable is declared inside a procedure,it is created and destroyed everytime the procedure is executed.
Declaring variables in ASP and assigning values to them
| <%@language-“javascript”%> <html><head></head><body> <% var name var age var salary name=”XYZ” age=35 salary=4500 Response.Write(“My name is : “+name) Response.Write(“My age is : “+age) Response.Write(“My salary is : “+salary) %></body></html> |
OUTPUT:
My name is XYZ
My age is 35
My salary is 4500
ASP procedures:
<%@ language="javascript" %> |
