ASP - VBScript

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: 10/26/2013

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: 10/26/2013

No comments:

Post a Comment