Response Object in Classic ASP

The Response object in Classic ASP controls the HTTP response sent to a visitor: text and HTML output, buffering, redirects, headers, and when processing ends. Choose the method that matches what the server must do.

The most common starting point is Response.Write:

<%
Response.Write "Hello from Classic ASP!"
%>

Output: Hello from Classic ASP!. Save the snippet in a .asp page on an IIS site with Classic ASP enabled; the enclosing page template is written in PHP only for the Plus2Net website.

On this page — Show page sectionsHide page sections

Response object methods at a glance

MethodWhat it doesExample tutorial
Response.WriteAdds text or markup to the response bodyWrite output
Response.FlushSends currently buffered output while continuing processingFlush output
Response.ClearDiscards output still in the ASP bufferClear output
Response.EndStops processing this ASP file and returns its current resultEnd processing
Response.RedirectTells the browser to request a different URLRedirect
Response.BufferControls whether ASP holds body output before sending itBuffering guide

Write plain text and trusted HTML

<%
Response.Write "Welcome to Plus2Net"
Response.Write "<p>Learn Classic ASP step by step.</p>"
%>

The first statement writes text; the second writes an actual HTML paragraph. Response.Write does not automatically add a newline or encode visitor-provided text.

Safely display user input

<%
Dim visitorName
visitorName = Request.QueryString("name")
Response.Write "<p>Hello, " & Server.HTMLEncode(visitorName) & "</p>"
%>

Use Server.HTMLEncode() for text placed inside HTML elements. Attribute values, JavaScript, CSS and URLs have separate encoding and validation needs; do not treat HTML encoding as a universal sanitizer.

Buffer, flush, and clear

<%
Response.Buffer = True
Response.Write "This first message is sent.<br>"
Response.Flush
Response.Write "This second message is discarded.<br>"
Response.Clear
Response.Write "This final message is returned.<br>"
%>

The first message has already been flushed, so Response.Clear cannot remove it. The second is cleared before delivery; the final message is sent when the ASP page completes.

Stop processing with Response.End

<%
Response.Write "Before End"
Response.End
Response.Write "Never executed"
%>

Once the End method runs, the remaining statements in that ASP file are skipped.

Redirect to another tutorial

<%
Response.Redirect "/asp-tutorial/response-write.php"
%>

A redirect must occur before the HTTP headers have been committed. If you are deciding whether to redirect after a login or form submission, perform that decision before writing or flushing page content.

How buffering changes behavior

With buffering enabled, ASP can hold page output until completion. Calls to Flush transmit pending output and can commit headers; Clear removes pending output; End stops execution. In current IIS Classic ASP configuration, buffering is normally enabled unless changed by an administrator. See Response buffering.

Important distinction: These are Classic ASP Response methods. Do not copy ASP.NET examples such as Response.Redirect(url, false), CompleteRequest(), or Server.Transfer() into a VBScript Classic ASP lesson; their APIs differ.

Which method should I use?

GoalUse
Print a variableResponse.Write
Send partial buffered output before work finishesResponse.Flush
Discard unsent markup before replacing itResponse.Clear
Stop the current page immediatelyResponse.End
Move the browser to another addressResponse.Redirect

Troubleshooting

If a redirect reports a header error, check whether output has already been flushed. If Flush reports buffering off, enable buffering before sending content. If HTML characters supplied by a visitor become active markup, encode the value for its HTML output context. If code after End is not executed, that is expected.

Frequently asked questions

Does Response.Write immediately send text to the browser?

With buffering enabled, it normally adds output to the buffer. The server sends it later or when Response.Flush is called.

Will Response.Clear undo a previous Response.Flush?

No. It can only discard output still buffered on the server.

Does Response.Redirect change the page on the server?

No. It tells the client to make a new request at the target URL; it is not a server-side include.

Can a Classic ASP page output HTML and text?

Yes. Use Response.Write to send trusted markup or HTML-encoded text.

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