Response.Flush sends the data currently held in the Classic ASP response buffer, then allows the ASP page to continue executing. It is useful when a lengthy operation should send an early response instead of waiting for the page to finish.
<%
Response.Buffer = True
Response.Write "Message No 1: Before Flush<br>"
Response.Flush
Response.Write "Message No 2: After Flush<br>"
%>
The page ultimately contains both messages. The first is flushed before the second is generated; on a fast page the visitor may still see both appear together.
Response.Flush
Response.Buffer = True before generating output, or enable buffering in IIS configuration. A Flush call with buffering disabled produces an ASP buffering error.The original lesson showed the following representative error when attempting to flush with buffering disabled:
Response object error 'ASP 0159 : 80004005'
Buffering Off
Buffering must be on.
Set Response.Buffer early in the request. For the IIS server setting and additional examples, see buffering in Classic ASP.
<%@ Language="VBScript" %>
<% Option Explicit
Response.Buffer = True
Dim i
%>
<!DOCTYPE html>
<html lang="en">
<head><meta charset="utf-8"><title>Flush demo</title></head>
<body>
<%
Response.Write "Message No 1: Before Flush<br>"
Response.Flush
Response.Write "Message No 2: After Flush<br>"
%>
</body>
</html>
Save this as flush-demo.asp on IIS. Unlike the PHP file that displays this tutorial, the example itself is Classic ASP.
The original tutorial simulated slow processing with a long For...Next loop:
<%
Dim i
Response.Write "Message No 1: Before Flush<br>"
Response.Flush
For i = 1 To 100000000
Next
Response.Write "Message No 2: After Flush<br>"
%>
<%
Response.Buffer = True
Dim batchNo
For batchNo = 1 To 3
Response.Write "Batch " & batchNo & " complete<br>"
Response.Flush
Next
%>
This illustrates the order in which output is sent; do not assume a progress interface will update in real time without testing the actual client and proxy configuration.
| Method | Buffer action | Script continues? |
|---|---|---|
Response.Flush | Sends pending body output | Yes |
Response.Clear | Discards pending body output | Yes |
Response.End | Stops processing and returns current result | No |
<%
Response.Buffer = True
Response.Write "Content sent already"
Response.Flush
' Do not call Response.Redirect here.
%>
After flushed output commits the headers, you cannot issue a normal Response.Redirect or change HTTP headers. Make redirect decisions before flushing the page.
<%
Response.Buffer = True
Dim labelText
labelText = Request.QueryString("label")
Response.Write Server.HTMLEncode(labelText)
Response.Flush
%>
Flushing does not make unsafe markup safe. Encode visitor text before writing it to the HTML document.
If the page reports ASP 0159, check Response.Buffer. If the browser shows the whole page at once, investigate browser/proxy buffering and test with real slow work rather than a CPU-intensive delay loop. If the script crashes after a flush, the bytes already sent cannot be recalled with Response.Clear.
No. It sends the current buffer and the ASP script continues.
Yes, but Clear only removes content written after the flush that has not yet been sent.
No. For normal short pages, allowing the buffered response to complete naturally is often simpler.
Browsers, proxies and network buffering may delay visible rendering even though ASP has flushed data.
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.