When you think ASP, think...
Recent Articles
All Articles
ASP.NET Articles
ASPFAQs.com
Message Board
Related Web Technologies
User Tips!
Coding Tips

Sections:
Sample Chapters
Commonly Asked Message Board Questions
JavaScript Tutorials
MSDN Communities Hub
Official Docs
Security
Stump the SQL Guru!
XML Info
Information:
Feedback
Author an Article
ASP ASP.NET ASP FAQs Message Board Feedback
Print this page.
The Response Object


One of the most important objects in ASP is the Response object. It is the object which communicates between the server and the output which is sent to the client. To write an ASP page, all you need to do is write a standard HTML page, putting in the Active Server Pages script where needed. Active Server Pages script is denoted by the text between <%'s and %>'s.

To send ASP to the client, you need to use the Response object. The method of the Response object which sends data to the client is the Write method. For example, if you write an HTML page which looks like:

<%@ LANGUAGE="VBSCRIPT" %>
<HTML>
<BODY>
   <% Response.Write("Hello, World!") %>
</BODY>
</HTML>

if a user views the page with a standard browser, they will see the text, "Hello, World!" on the screen. It's as if you had just written an HTML page with the words "Hello, World!" where the <%'s the text between and the %>'s were. Of course, unlike an HTML page which is sent directly to the client, this page has passed through the server's ASP.DLL, parsing it so that instead of the client seeing <% Response.Write("Hello, World!") %>, the client merely sees "Hello, World!" Even if the user goes to View Source in their browser, they will only see the "Hello, World!" This is because the client is never sent the preprocessed ASP script.

You can inherently invoke the Response.Write method by using the equals (=) sign. Here is an example, which happens to produce the exact same output as above:

<%@ LANGUAGE="VBSCRIPT" %>
<HTML>
<BODY>
   <%="Hello, World!" %>
</BODY>
</HTML>

As you notice, we just got rid of the Response.Write( ... ), but left the stuff in between. The = simulates Response.Write.

There are also a few other neat properties in the Response object. One is Expires, which sets how soon your page expires. Many modern browsers cache pages for quicker downloading times. You can use ASP to set how often the browser checks to see if it needs to redownload the page. You set it in terms on minutes. If you want to browser not to cache the page, you can set Response.Expires = 0. Let's look at an example where we set the page to expire in 10 minutes.

<%@ LANGUAGE="VBSCRIPT" %>
<%
   Response.Expires = 10
%>

<HTML>
<BODY>
   This page will expire in 10 minutes
</BODY>
</HTML>

Pretty neat, eh? Another neat property of the Response object is the Buffer property, which takes either a true or false value. If buffer is set to true, the server processes the entire ASP script before sending any of the file to the client. If buffering is set to false (which it is by default), the server will send data to the client as it processes it. Below is an example of setting buffering to true:

<%@ LANGUAGE="VBSCRIPT" %>
<%
   Response.Buffer = true
%>

<HTML>
<BODY>
   This page's output to the client was buffered
</BODY>
</HTML>

FAQ Table of Contents   ASP's Server Side Languages Variables in ASP 


ASP.NET [1.x] [2.0] | ASPMessageboard.com | ASPFAQs.com | Advertise | Feedback | Author an Article