I.T. Discussion Community!
-Collapse +Expand
ASP Classic
Search ASP Classic Group:

Advanced
-Collapse +Expand ASP Classic Store

Prestwood eMagazine

July Edition
Subscribe now! It's Free!
Enter your email:

   ► KBWebsite Scri...ASP ClassicLanguage Det...   Print This     
  From the October 2015 Issue of Prestwood eMag
 
ASP Classic Language Details:
Response.Flush and Response.Buffer
 
Posted 12 years ago on 12/19/2006 and updated 4/10/2010
Take Away:

Response.Flush sends the contents of the buffer to the browser. This command is useful for showing a visitor something while slow loading pages load.

KB100421



In ASP, the Response object sends output to the client browser. You can use the Response.Buffer property to indicate whether the page output is buffered. If buffered, all scripts on the page will finish processing unless you specifically call either the Flush or End method. You can set the buffer in IIS or in code using the Buffer property.

For example:

Response.Buffer = True

If the Response.Buffer property is set to True, the Flush method immediately sends all current buffered page content to the client. IIS then stops processing ASP code and waits for the browser to ping back (a very fast procedure). The use of Response.Flush is a fairly common technique for showing a page background image and page header nearly immediately to a visitor while the rest of the page is rendered. This gives visitors the feeling of a more responsive website.

Proper Use of Flush:

Response.Buffer = True
''' ...some code that outputs here (perhaps a header and body background image)
Response.Flush

Note: If the Flush method is called, the server does not honor Keep-Alive requests for that page.

If Buffering is Off, Flush Returns an Error

If Response.Buffer is False, then Flush will return the following runtime error.

Response object error 'ASP 0157 : 80004005' 
Buffering On
/home.asp, line 15
Buffering cannot be turned off once it is already turned on.

Response.Buffer Default

In IIS 5 and above, the default for Response.Buffer is True. In IIS 4 and earlier, the default was False.

Redirects MUST come before Flush

However, once you've called Response.Flush, you cannot use Response.Redirect to redirect to another page. Therefore, all your processing that might lead to a redirect needs to occur BEFORE you call Response.Flush. I think that's okay, because your code is cleaner anyway.

This code will fail...

Response.Flush
Response.Redirect "/"

With this error:

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

Cookies and Flush

Because cookies must be written before any HTML output, you need to handle cookies prior to calling Response.Flush.

Calling Flush Multiple Times

You can use Response.Flush to show the top of your page so your visitor can start reading your page.
--Mike Prestwood

You can use Response.Flush to show the top of your page so your visitor can start reading your page. This is a common technique around tables. Because browsers render ONLY after an end table tag, it is a common technique to call Response.Flush after the table end tag and prior to starting a new table.

You can call Response.Flush as many times as you want. However, because the browser must ping back to the server, it is a best practice to limit the use of Response.Flush to just a few per page. You definately don't want to call it every time you loop through a table of say 1,000 records.


Comments

1 Comments.
Share a thought or comment...
Comment 1 of 2

how to use response.redirect after using response.buffer

---
Naresh
Posted 42 months ago

Comment 2 of 2
Hi, Response.Buffter = false; Response.Write("Some Message"); Response.flush(); the above code working fine in my colleague system, but in my system not working. Why?
---
sdfsdf
Posted 26 months ago
 
Write a Comment...
...
Sign in...

If you are a member, Sign In. Or, you can Create a Free account now.


Anonymous Post (text-only, no HTML):

Enter your name and security key.

Your Name:
Security key = P1162A1
Enter key:
KB Post Contributed By Mike Prestwood:

Mike Prestwood is a drummer, an author, and creator of the PrestwoodBoards online community. He is the President & CEO of Prestwood IT Solutions. Prestwood IT provides Coding, Website, and Computer Tech services. Mike has authored 6 computer books and over 1,200 articles. As a drummer, he maintains play-drums.com and has authored 3 drum books. If you have a project you wish to discuss with Mike, you can send him a private message through his PrestwoodBoards home page or call him 9AM to 4PM PST at 916-726-5675 x205.

Visit Profile

 KB Article #100421 Counter
35272
Since 4/2/2008
-
   Contact Us!
 
PrestwoodBoards.com was developed and is maintainted by me. Do you have a question or suggestion? Do you see a problem? Contact me now. My goal is to build an ad-free and spam-free source of I.T. information with many contributers (ok to promote your website/company in your bio). Yes, my company Prestwood IT Solutions is mentioned in my bio which shows with every post, but you can contribute and promote your pet project too!

1,966 People Online Now!!  
Sign In to see who's online now!  Not a member? Join now. It's free!
Show more stats...


©1995-2018 PrestwoodBoards  [Security & Privacy]
Professional IT Services: Coding | Websites | Computer Tech