ASP Programming - VBScript
As was mentioned in the last lesson, ASP uses VBScript as its default scripting language. VBScript is similar to Javascript, a client side programming language used to add functionality through the <script> tag.Read the following paragraph carefully!
VBScript, when used to program ASP converts it to server side scripting. Any given web page could be created from a combination of server side and client side scripting. The confusing part is this: You must use these client side scripting languages (Javascript, VBScript, etc) to program in ASP!
Below we have a simple ASP script programmed in VBScript and includes the necessary HTML as well. This is only server-side scripting.
Server Side ASP Code using VBScript:
<html> <body> <% Dim myString myString = Date() Response.Write("The date is: " & myString) %> </body> </html>
Display:
The date is:
4/20/2012
If you already know VBScript or Visual Basic programming then you'll recognize
Dim as Dimension, which is used to "dimension" variables. It is a good programming
practice to "dimension" all your variables before you use them, as we did with myString in the
above example.
Now that we have our ASP Code working, say that we wanted to use our ASP code along with some client side Javascript code. To keep it simple we are just going to use the Javascript write function and have our ASP Code fill in the Date. All the Javascript client code is in the default color, but ASP Server Side Code is in Red.
ASP Code with VBScript and Client Side Javascript Code:
<script>
document.write("The date is:<%
Dim myString
myString = Date()
Response.Write(myString)
%>")
</script>
Display:
The date is:
4/20/2012
If you just want to program in ASP you can disregard the above
example if you find it confusing.
Just remember that you can have client-side Javascript code and
server-side ASP/VBScript code included in an ASP generated web page!
0 comments:
Post a Comment