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.
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.
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.
| Step | Server action | Visible at completion? |
|---|---|---|
| Write message 1 | Pending in buffer | Yes, after Flush |
| Flush | Send message 1 | Yes |
| Write message 2 | Pending in buffer | No, cleared next |
| Clear | Discard message 2 | No |
| Write message 3 | Pending in buffer until page finishes | Yes |
<%
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.
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.
| Method | Effect |
|---|---|
Clear | Discard unsent output; continue processing |
Flush | Send pending output; continue processing |
End | Stop ASP execution; return current result |
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.
No. Flushed content has already been sent to the client.
No. Execution continues; use Response.End if termination is required.
No. Buffering controls whether output is accumulated; Clear discards pending body content.
You can redirect while headers have not been committed. Clearing content cannot reverse an earlier Flush.
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.
| 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. | |