[Introduction][The
Browser's Result of a Computed ASP page][Personal
Web Server][Sending Data to the user]
Sending Data to the user
Usually the content of a page is ent from the server
to the client immediately line by line, during the script's processing.
There are cases though, in which we want to buffer the
output, to do some manipulation of it, for example to delete it.
We can use Response Expires even after HTML code or response
write statements.
A buffer is a storage capable of holding data for a certain amount
of time before relesing the data. The buffer can be controlled.
Basic ASP objects
Using VBScript, we have access to all the
standard VB script objects, any ActiveX DLL's we make in VB5 - and the
standard ASP objects.
The two most important standard ASP objects
are the Request and Response objects.
The Request objects allows you to interrogate
the URL command line, request.querystring("key"). To request
information from a form, request.form("inputname"). Also to
retrieve cookies (data stored on the clients machine), request.cookies("key")("data").
The Response object allows you to write to
the HTML file. A shorthand version of Response.write "string"
is to just simply use an =, you can write a cookie, response.cookies("adv")("data")="string".
ASP Variables
Variables are used to store information. This example demonstrates how
to create a variable, assign a value to it, and insert the variable value
into a text.
<html>
<body>
<%
Dim name
name="Jan Egil"
response.write("My name is: " & name)
%>
</body>
</html>
This examples shows that the server will buffer the page output,
and wont send a response to the browser until the ASP script has been
processed or until Flushor End method has been called.
Response. Expirres =60 means that the expiration time is 60 minutes.
This is helpfull when we expect that the dynamically created content
change at least every hour.
Response. Flush forces the server to send any buffered ouput to the
client immediately.
Array
Arrays are used to store a series of related data items. This example
demonstrates how you can make an array that stores names.
<html>
<body>
<%
Dim famname(5)
famname(0) = "Jan Egil"
famname(1) = "Tove"
famname(2) = "Hege"
famname(3) = "Stole"
famname(4) = "Kai Jim"
famname(5) = "Borge"
For i = 0 to 5
response.write(famname(i) & "<br>")
Next
%>
</body>
</html>
Looping through headers
This example demonstrates how you can loop through the 6 headers in
HTML.
<html>
<body>
<%
Dim i
for i = 1 to 6
response.write("<h" & i & ">This is header
" & i & "</h" & i & ">")
next
%>
</body>
</html>
Examples
Time Based Greeting in VBScript
How to write VBScript syntax in ASP. This example will display a different
message to the user depending on the time on the server.
<html>
<body>
<%
Dim h
h = hour(now())
If h < 12 then
response.write("Good Morning!")
else
response.write("Good day!")
end if
%>
</body>
</html>
Time Based Greeting in JavaScript
How to write JavaScript syntax in ASP. This example is the same as
the one above, but the syntax is different.
<%@ language="javascript" %>
<html>
<body>
<%
var d = new Date()
h = d.getHours()
if (h < 12)
{
Response.Write("Good Morning!")
}
else
{
Response.Write("Good day!")
}
%>
</body>
</html>
|