Managing Buffer to post data outputs to client side

Response buffering controls whether generated page output is held on the server or sent progressively to the client. With buffering enabled, ASP can accumulate output and later flush, clear or redirect before the buffered response is committed.



If buffering is disabled, output can be sent as it is generated. When buffering is enabled, output is held until the page completes or Response.Flush sends it. Current IIS Classic ASP configuration enables buffering by default.



We have to set the status of buffer before any output is posted, otherwise we will get error message. So best is to set the buffer status at the staring of the page. Any output if coming due to any warning or error message in script part will create problem if we keep the buffer just before the html tags.

The best way to test the buffer effect is to check the date and time up to seconds level by using now function and printing to screen.
<%@ Language=VBScript %>
<% Option Explicit %>
<% Response.Buffer = TRUE %>

<html><head>
<title>(Type a title for your page here)</title>
</head>
<body >

<%
Dim i,j
Response.Write(now)

For i=1 to  10000000
j= j+1  'to waste some time
Next 

Response.Write "<br>" & now
%>

</body>
</html>
Here in the above code two places the data or the output is to be posted to the user browser. Both the data are current date and time. So we can see the difference in seconds. If in your case the difference is too short or too high then adjust the looping number by changing number if zeros in for loop. Here you can see the for loop is there only to add some delay between two response.write statements printing the date and time to the user screen.

Here as buffer is ON (Response.Buffer = TRUE ) so you can see two different times getting displayed on the screen at a single instance of time.

Note: The loop in this example only creates a visible delay for learning purposes; it is not a production waiting technique.

Here both times or time outputs are stored in buffer and posted at one go once the script execution is over.

Try the same code with buffer is OFF or false . Change this line only and keep it as False.

<% Response.Buffer = False %>
You can see the difference as first one output of time will come and after some time the other out put of time will come ( change the value of looping in for loop if gap is more or too less, this is to adjust delay ). Here each line is posted immediately without waiting for the full page to complete its execution.

If we keep the buffer Off and then send output and then try to make the buffer On then we will get an error message like this
Response object error 'ASP 0156 : 80004005' 
Header Error 
The HTTP headers are already written to the client browser. Any HTTP header modifications must be made before writing page content. 
Similarly we can't make buffer False when it is On before and send some output in between. Here is the error message we will get
Response object, ASP 0157 (0x80004005)
Buffering cannot be turned off once it is already turned on.

ASP Home






✖
We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
© 2000-2026 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer