Response.Flush in Classic ASP

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.

On this page — Show page sectionsHide page sections

Syntax and prerequisite

Response.Flush
Prerequisite: Response buffering must be enabled. Set Response.Buffer = True before generating output, or enable buffering in IIS configuration. A Flush call with buffering disabled produces an ASP buffering error.

Original buffering-off 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.

Complete standalone Flush example

<%@ 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.

Demonstrate partial output with a loop

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>"
%>
Demonstration only: A 100-million-iteration empty loop consumes CPU and should not be used as a timing mechanism in a real application. Browser rendering, reverse proxies, buffering layers and network conditions can also prevent visibly incremental output.

Flush after a batch of work

<%
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.

Flush versus Clear versus End

MethodBuffer actionScript continues?
Response.FlushSends pending body outputYes
Response.ClearDiscards pending body outputYes
Response.EndStops processing and returns current resultNo

Why redirecting after Flush fails

<%
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.

Keep user content safe

<%
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.

Common errors and debugging

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.

Frequently asked questions

Does Response.Flush end script execution?

No. It sends the current buffer and the ASP script continues.

Can I use Response.Clear after Flush?

Yes, but Clear only removes content written after the flush that has not yet been sent.

Is Response.Flush required for every ASP page?

No. For normal short pages, allowing the buffered response to complete naturally is often simpler.

Why do both messages appear together?

Browsers, proxies and network buffering may delay visible rendering even though ASP has flushed data.

Back to top ↑


ASP Home






✖
We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
© 2000-2026 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer