docs:programming:asp:response_object

Response Object

The response object is useful, feature rich, and subtle. We are going to focus on it's most fundamental capabilities – the 20% you will use 80% of the time. The capabilities we think are vital include:

  • response.write
  • response.write alternate syntax <%= %> which allows ASP simply placed in HTML
  • response.end which effectively halts a script in it's tracks.
  • response.redirect which transfers control to another page

Does this error message plague you?

Response object error 'ASP 0156 : 80004005' 
Header Error 
whatever.asp, line # 
The HTTP headers are already written to the client browser. Any HTTP
header modifications must be made before writing page content. 

The Simple Fix….

<%response.buffer=true%>

needs to be added as the very first line to any pages made by any HTML document that mixes redirects/headers and content. And buffering is a great idea anyway from overall server speed viewpoint see http://www.learnasp.com/advice/whybuffer.asp).

One drawback to <%response.buffer=true%> is if a page takes a while to compose (i.e. a couple thousand records from a database) people see nothing until the page is completely rendered. If a page takes 20 seconds to render, the browser user sees nothing until the 20th second! In that situation to avoid appearing as the page is dead, a well-placed <%response.flush%> tell server to send HEADER + whatever text so far so lets readers see the portions of the page being built. Increasing percieved speed of database displays is explained at http://www.learnasp.com/learn/speedtables.asp by judicous use of flushing buffer.

NT4 <%buffer=false%> by default which hurts overall server speed (http://www.learnasp.com/advice/whybuffer.asp). Win 2000 <%buffer=true%> by default. A clever administrator can change NT4 registry so buffer=true for all scripts and will see major server performance improvements (see http://www.learnasp.com/learn/speedserver.asp for other ones).

response.write server.htmlencode("<B>Hyperion</b> by <I>Dan Simmons</i> is a great novel")
response.write server.URLencode("Joe Smith & Hilda = a team")

The response object is often used with a variety of syntax variations which we will detail here.

<html><head>
<title>res4.asp</title>
</head><body bgcolor="#FFFFFF">
<%
' The response object can be used to write text a variety of ways
' depending on what style you personally prefer
 
' Various permutations of writing to the browser
response.write "<form>"
response.write "Hello, Joe<br>"
 
who="Joe"
response.write "Hello, " & who & "<br>"
%>
 
Hello, <%=who%><br>
 
Which Book? <input type="TEXT" name="book" value="The Stand"><br>
 
<%
response.write "Which Book? <input type=""TEXT"" name=""book"" value=""The Stand""><br>"
%>
 
<%
response.write "Which Book? <input type='TEXT' name='book' value='The Stand'><br>"
%>
 
<%
quote=chr(34)
response.write "Which Book? <input type=" & quote & "TEXT" & quote & " name=" & quote & "book" & quote & " value=" & quote & "The Stand" & quote & "><br>"
%>
 
 
<%bookname="The Stand"%>
Which Book? <input type="TEXT" name="book" value="<%=bookname%>"><br>
 
<%
response.write "Which Book? <input type=""TEXT"" name=""book"" value=""" & bookname & """><br>"
%>
</form>
</body></html>
  • docs/programming/asp/response_object.txt
  • Last modified: 2008/08/03 00:25
  • by 127.0.0.1