Response.Flush object to send outputs

ASP engine sends data to client browser after completing the script execution of the page. That is the reason we get blank pages for some time when there is lot of script execution is going on at server end. To avoid such a situation where user may think some thing has gone wrong , we can send some output at the starting of the script execution asking visitors to be patient. All these can be achieved by managing buffer and sending the outputs at any time by using Response.Flush object. Here the flush command will depend on Buffer so if the buffer is off then we will get error message like this .

Response object error 'ASP 0159 : 80004005'
Buffering Off
/a/response/flush.asp, line 15
Buffering must be on.

You can read more on ASP buffer here. In advanced ASP engines buffer is ON by default. Now let us try with some examples to show how Response.Flush works.

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

%>

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

<%
Dim i
Response.Write("Message No 1 : Before Flush <br>")
Response.Flush
Response.Write("Message No 2 : After Flush <br>")
%>

You will get two lines of out put ( Message No 1 & Message No 2 ) , you will not able to experience the difference between Message No 1 & 2 as the code is very small and it will be executed fast. Now we will introduce some delay by using a for loop so you can see the time gap between two line of messages. You may have to adjust the delay time by changing the upper value depending on your system. Here is the code.

<%
Dim i
Response.Write("Message No 1 : Before Flush <br>")
Response.Flush
For i=1 to 100000000
Next
Response.Write("Message No 2 : After Flush <br>")
%>

You will get the first Message ( No 1 ) as response.Flush will send the output from buffer to client machine. Then after the time delay ( because of for loop ) you will get the second message line. Try the same script again by removing ( or commenting ) the Response.Flush line. You will see both the lines of message after the time delay when script execution is over.

The difference between Response.Flush and Response.Clear is in former case the data is posted to client machine and then removed from buffer, in later case data is removed from buffer without sending to client browser.

Be the first to post comment on this article :




Google+

Post Comment This is for short comments only. Use the forum for more discussions.




HTML . MySQL. PHP. JavaScript. ASP. Photoshop. Articles. FORUM Contact us
©2000-2018 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer