ProgrammerGuide.Net | Step by Step Programmer Guide

ASP Response Object

Response Object,

What is Response Object?
The Response Object is one of the six built-in ASP objects. Response is used to send output to the client. This output might be text displayed in a browser window, cookie data, or it might have to do with how your pages are sent to the client and stored.

Dissecting the Response Object
Response allows you to send information to the browser and control how information is send to the browser. It has several methods and properties. This section covers about half of them. The other are more advance and much less commonly used

Sending HTML to the Browser
The most common use of the Response Object is to send data to the client’s Web browser to be displayed as part of a web page. It does this in two different ways. The first is to use the Write method and the other is used the shortcut <%=…….%>

One important issue in using Response.Write is that the string being written cannot contain “%>”. If you need to write a string that contain “%>”, Use  “%\>”, Since we use %> to indicate the end of a block of ASP code, putting it in your string will confuse system. The following example demonstrate the different ways of send text containing quotations marks. It also demonstrate the use of Server .HTMLEncode to send text so that the browser dose not interpret it.

<%@ Language=VBScript %>
<% Option Explicit %>
<HTML>
  <Body>
    <A HREF=”index.html”>Click here</a>
    <BR>
<%
    Response.Write(“<A HREF=””index.html””>Click here</a>”)
    Response.Write(“<BR>”)
    Response.Write(“<IMG SRC=””banner.gif””>”)
    Response.Write(“<BR>”)
    Response.Write(“<A HREF=””banner.html””>Click to enlarge image</a>”)
    Response.Write(Server.HTMLEncode(“<BR>”))
%>
   </BODY>
</HTML>

Buffering ASP Pages
In addition to sending output to the clients, Response can control how and when output is send to the client. Output can be sent in two different ways: buffered and unbuffered. Unbuffered output is sent immediately. Buffered output is not sent until the script is finished, or until a special command is given to send it. Without buffering , the first Response.Write at top is send immediately before the latter Response.Write is executed.

Response.Buffer = True turns on buffering and Response.Buffer = False turns it off. You must be careful, though. If you want to set buffering, you must do it before you sent any output. Put it up at the top, immediately after the Option Explicit. Buffering may seem unimportant. In most of your pages, the buffering setting will not matter. In some circumstances it is helpful to be able to specify it, though. If you have a page that will take a long time to finish processing, you might want to turn off buffering so that user can start reading part of your output while the rest is processing. The following example demonstrate you the buffer at work. It shows how output can be generated at two different times, yet arrive at client together.

<%@ Language=VBScript %>
<% Option Explicit %>
<% Response.Buffer = True %>

<HTML>
  <BODY>
<%
    Dim lngCounter, lngTimeWaster
    Response.Write(“It is now: ” & Now)
    Response.Write(“<BR>”)
   
    For lngCounter = 1 to 5000000
        lngTimeWaster = lngTimeWaster + 1
    Next

    Response.Write(“It is now: ” & Now)
%>
  </BODY>
</HTML>

Also try remove line 3 “<% Response.Buffer=True %>”, You will see the difference in how it loads into your browser.

Please click here for related products on Amazon!

Jayashee

Add comment

Want to Check Celebrities News?