Response.Clear in Classic ASP

Response.Clear discards content that is still in the Classic ASP output buffer. The method does not erase data that was already sent to the browser, and the page continues executing after the buffer is cleared.

<%
Response.Buffer = True
Response.Write "This message is removed."
Response.Clear
Response.Write "This message is displayed."
%>

Output: This message is displayed. The first message never leaves the pending response buffer.

On this page — Show page sectionsHide page sections

Syntax and buffering requirement

Response.Clear

Buffering must be enabled for Response.Clear. Configure Response.Buffer = True early in the page, before sending output, or use the IIS buffering setting.

Original example: Flush, then Clear

The original lesson demonstrated three messages in a complete Classic ASP page. It is useful for understanding that Clear cannot undo Flush:

<%@ Language="VBScript" %>
<% Option Explicit
Response.Buffer = True
%>
<!DOCTYPE html>
<html lang="en">
<head><meta charset="utf-8"><title>Clear and Flush</title></head>
<body>
<%
Response.Write "Message No :1 Before Clear and Flush <br>"
Response.Flush
Response.Write "Message No :2 After Flush and before Clear <br>"
Response.Clear
Response.Write "Message No :3 After Clear and flush <br>"
%>
</body>
</html>

Only Message No 1 and Message No 3 appear. Message 1 was already flushed; Message 2 was discarded; Message 3 remains in the final response.

How pending output changes

StepServer actionVisible at completion?
Write message 1Pending in bufferYes, after Flush
FlushSend message 1Yes
Write message 2Pending in bufferNo, cleared next
ClearDiscard message 2No
Write message 3Pending in buffer until page finishesYes

Clear and replace a draft response

<%
Response.Buffer = True
Dim showAlternate
showAlternate = True
Response.Write "Default content"
If showAlternate Then
  Response.Clear
  Response.Write "Alternate content"
End If
%>

If the condition is true, only Alternate content is delivered. In most applications, deciding what to render before writing HTML is simpler; this is an illustration of the buffer behavior.

Clear does not reset HTTP headers

Response.Clear discards buffered body output, not an already committed status line or HTTP headers. If headers were already sent—typically after Response.Flush—you cannot undo their delivery with Clear.

<%
Response.Buffer = True
Response.ContentType = "text/plain"
Response.Write "First draft"
Response.Clear
Response.Write "Final text response"
%>

The content type remains text/plain; the body contains only Final text response.

Clear versus Flush versus End

MethodEffect
ClearDiscard unsent output; continue processing
FlushSend pending output; continue processing
EndStop ASP execution; return current result

Common errors

If buffering is disabled, Response.Clear cannot clear unsent output. If a flushed message still appears, that is expected. If the goal is to stop execution as well as remove output, combine a deliberate clear with Response.End only when terminating the whole request is appropriate.

Frequently asked questions

Can Response.Clear remove text after it was flushed?

No. Flushed content has already been sent to the client.

Does Response.Clear stop the ASP page?

No. Execution continues; use Response.End if termination is required.

Is Response.Clear the same as Response.Buffer = False?

No. Buffering controls whether output is accumulated; Clear discards pending body content.

Can I redirect after Response.Clear?

You can redirect while headers have not been committed. Clearing content cannot reverse an earlier Flush.

Back to top ↑


ASP Home



tahzeeb

26-04-2013

thank. Bt i want an example of y n where do we use response.clear. Plz give a practical example.
Larry De Angelis

24-06-2015

Thank you for the several helpful tips and tricks. I found them to be shoet and sweet, and they get right to the point.



✖
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