views:

210

answers:

2

When to use Response.Flush? Do I need to call it every time before I call Response.End?

+1  A: 

You don't need to call Respond.End in most cases. If you do, you have to know about your case and why are you calling Respond.End and about Flush. It is very case specific.

Also, MSDN cleared it out:

If Response.Buffer is set to TRUE, calling Response.End flushes the buffer. If you do not want output returned to the user, you should first call Response.Clear.

lak-b
I'm doing Response.Clear();Response.Write("Output that i want to Pass");Response.Flush();Response.End();Is it right?or i should not call response.Flush()
Ismail
No, you shouldn't call Flush() before End() in this case. Flush() will call automatically inside End().
lak-b
+2  A: 

The Response.Flush method is used when you want to flush part of the content before the rest of the page. To have any effect response buffering has to be turned off, and you have to output the page content yourself using Response.Write rather than using aspx markup.

Guffa
This almost sounds like an answer to my question. A small clarification required though. When I say Response.End(); does it automatically flushes out the response I have written (by calling Response.Write()) till now or I have to call Response.Flush() before Response.End()?
Ismail
@Ismail: The documentation only says that `Flush` is called automatically when buffering is on, it doesn't say if this happens when buffering is off. So, it's not needed when buffering is on, but it might be needed when buffering is off. If you let the page cycle end normally without calling `Response.End` the content will always be flushed automatically.
Guffa