homecode zoneQuick Codedownloadssubmit codeabout usfeedbackscontact ussitemap
 
Beginners
General
Advance Scripting
Database
Function
Variables
Response Object
Request Object
ASP Components
Using Database
Pro - Languages
C/C++
Java
Visual basic
asp
vb.net 2003/2005
asp.net
Quick Code
SUBMIT CODE
Mail List
LINKS
Submit LINK
 
ProgrammerGuide.net - ASP Response Object.
Home » ASP Zone » ASP-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 .HTML Encode 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
 

« Previous 1 2 3 Next »

Viewers: 15
Visitors:127291
Last Updated on:Sunday, January 17, 2010
Home | About us | Feedback | Contact us | Sitemap
Copyright © 2008 ProgrammerGuide.net. All rights reserved.
This site is best viewed in IE 6.0, Firefox 1.5 and above with screen resolution of 1024 X 768.