Response object

M

masoud bayan

Hi,



I am developing an asp.net page that iteratively (inside a loop) calls a web
service at the backend and shows the result to user. For this purpose I
should update page with the web service response after each call to show a
progress to user. I used following code to test, but it does not work and
after user clicks on start button, page will not be refreshed with each
Response.Flush() call, and only after finishing the loop all information
will be shown together:



Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load



Response.Buffer = True

Response.BufferOutput = True

Response.CacheControl = "no-cache"

Response.AddHeader("Pragma", "no-cache")



End Sub



Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click



For i As Integer = 1 To 3

Response.Write(11111111111111 * i)

Response.Write("<br>")

Response.Flush()



System.Threading.Thread.Sleep(2000)

Next



End Sub



I am wondering why the response output is not being sent to browser until
the page processing is done. One interesting thing is, after first hitting
of start button when I press browser's F5 button (refresh) ,browser shows
page response line by line as it is supposed to work but again when I hit
start button it shows response all together. It could be browser caching
problem so I added two lines of the above code to disable cache but still
have this problem.



Any advice is appreciated.



Thanks

Masoud
 
S

Stefan

I don't understand how the approach could work.

I would think a browser refresh (meta http-equiv="refresh"
content="2;url=yoursite.com"/) would work for what you describe
(besides it does not hold your worker thread hostage for 6 seconds).
Or, if you want to do it more fancy use remote scripting aeh ajax - it
is well suited for stuff like progress bars.

Also, if you do not actually have to display any response data from
your ws calls, then you could simply do a javascript progress bar,
which runs for 6 seconds (giving the user the calming feeling of
progress happening) and then simply refresh (using a js timer).
 
M

masoud bayan

Thanks for your comment.
Think we have a loop, counting from 1 to 10 in the code behind and inside
that loop we have a sleep of two or three seconds for each loop count. Then
we want to show to user, progress of counter numbers as:

1
after 2 second :
1 2
after 2 second:
1 2 3
....

can you show me an example (or a link) that how we can imlement it with your
suggestion?
 
C

Cactus Corp.

Hi there
The renderer usually waits for end of response before sending
it to the client. This relates to the 'response buffer' feature.

You need to disable the response buffer at the beginning of
the page :

Response.Buffer = false;

This will make the server start sending output information to the
client before the end of the page is rendered.

For example try this:

-------------buffer.aspx -------------
Response.BufferOutput = false;
for(int i=0;i<10;i++)
{
Thread.Sleep(500);
Response.Write(i+"<br/>");
Response.Flush();
}
-------------------------------------

This will work on Firefox. There must be some client side
setting in IE which prevents displaying the page before its
content is completely returned...


Antonio
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,074
Latest member
StanleyFra

Latest Threads

Top