Response.End stops processing the current Classic ASP page immediately. Output written before it is returned; statements after it are not executed. Use it for an intentional early exit when the remainder of the page must not run.
<%
Response.Write "Message No 1: Before End<br>"
Response.Write "Message No 2: Also before End<br>"
Response.End
Response.Write "Message No 3: Never executed<br>"
%>
Only messages 1 and 2 appear. The third statement is unreachable because Response.End stops processing this ASP request.
Response.End
<%@ Language="VBScript" %>
<% Option Explicit
Response.Buffer = True
%>
<!DOCTYPE html>
<html lang="en">
<head><meta charset="utf-8"><title>Response.End</title></head>
<body>
<%
Response.Write "Message No :1 Before Flush <br>"
Response.Write "Message No :2 After Flush <br>"
Response.End
Response.Write "Message No :3 After End, not executed <br>"
%>
</body>
</html>
The original example described the first and second messages as “before/after Flush,” although no Response.Flush call was present. The important behavior is that both messages precede Response.End; the later output is skipped.
<%
Dim pageNo
pageNo = Trim(Request.QueryString("page"))
If Not IsNumeric(pageNo) Then
Response.Write "Provide a numeric page value."
Response.End
End If
Response.Write "Page parameter accepted."
%>
This demonstrates an early exit, not full numeric validation: IsNumeric accepts some formats you might not want for a page number. Validate integer range and format separately for a real application.
<%
Response.Buffer = True
Response.ContentType = "text/plain"
Response.Write "Task completed"
Response.End
%>
A plain-text response does not need additional HTML below the End statement.
<%
Sub ShowGreeting()
Response.Write "Hello from a procedure"
Exit Sub
Response.Write "Not executed in this procedure"
End Sub
ShowGreeting()
Response.Write "Page continues"
%>
Exit Sub leaves only the procedure. Response.End stops the whole ASP page. Use the narrower control-flow statement when the rest of the response should still run.
| Method | Purpose |
|---|---|
Response.End | Terminate current ASP script |
Response.Clear | Discard only buffered response body |
Response.Redirect | Tell the client to request a new URL; in Classic ASP it ends the current page response |
Statements below Response.End will not run. Close open database resources and complete necessary state changes before ending the response, or organize the code so early termination does not skip required work. Keep authentication and authorization checks at the start of protected pages.
If expected output is missing, check for earlier Response.End calls. If a redirect seems to require an extra Response.End, it generally does not—Classic ASP Response.Redirect itself ends the response. Do not confuse these methods with similarly named ASP.NET APIs.
It stops processing and returns the current ASP response; content already written before the call is part of that result.
No. Put required operations before it or use a narrower exit statement.
No, not in Classic ASP. Redirect itself terminates processing.
No. It stops processing. To end a session, use the Session methods such as Session.Abandon where appropriate.
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.