Page 251 - DCAP408_WEB_PROGRAMMING
P. 251
Unit 10: Working with Response Object
one later. Without buffering, the first one is sent to the client immediately before the latter Notes
Response.Write is executed. With buffering, though, all the output is collected in a buffer on the
server and sent at once.
Did u know? How Buffering Works in ASP?
Buffering controls how content is written out from ASP to the end user. It affects how
response.redirect works as well as the speed of your webpage!
Self Assessment
Fill in the blanks:
5. Response.Write writes a variable or text to the current ……………….. output as a string.
6. ……………….. output is not sent until the script is finished, or until a special command is
given to send it.
7. The use of Server. HTML Encode to send text so that the ……………….. does not interpret
it.
8. As the double quote (“) is used to indicate the beginning and end of a ………………..,
writing strings that contain double quotes can cause problems.
9. The most important thing in using ……………….. is that the string being written cannot
contain “%>”.
10.3 Response.Buffer
The buffer property is a Boolean property that determines whether the output of your ASP is
sent as it runs or it is stored until all the code is complete or the Flush method is called. It is a
Boolean property which means that it is set to true or false. Let’s take a look how a couple of code
blocks would differ based on the setting of the buffer property. The first code block is buffered.
<%
Option explicit
Response.Buffer =true
Response.Write “Running query..”
Dim conn
Dim RSTotal Sales
Set conn=server.createobject (“adodb.connnection”)
Conn.open “sales”, “sa”, “your password”
Set RSTotalSales=conn.Execute (Select Sum (total amount) as Total Sales”_
& “from sales”)
Response.Write RSTotalSales(“TotalAmount”)
%>
The scenario of this code block is that we are presenting a page that shows the total amount of
sales for all records in a database table. We will estimate that the query will take 20s to run. The
buffer is on. So when the code gets to this line:
Response.Write “running query..”
LOVELY PROFESSIONAL UNIVERSITY 245