Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Response.Clear in ASP.NET 3.5

Tags:

asp.net

I have recently upgraded some of my web applications to ASP.NET 3.5 by installing the framework on the server and setting up my web applications acrodingly and all is well, however.

On some pages, I want to clear the current contents of the response buffer with code like this:

Response.Clear();
// Output some stuff
Response.End();

But this now isn't working in 3.5 when it did in 2.0. I have also tried setting the response buffer to false but this didn't work either.

Can anyone let me know why it isn't working or if there is a work around?

like image 843
GateKiller Avatar asked Sep 15 '08 11:09

GateKiller


People also ask

What is response Clear () in asp net?

The Clear method erases any buffered HTML output. However, the Clear method erases only the response body; it does not erase response headers. You can use this method to handle error cases.

What does Response Buffer do?

The Buffer property indicates whether to buffer page output. When page output is buffered, the server does not send a response to the client until all of the server scripts on the current page have been processed, or until the Flush or End method is called.


1 Answers

Try setting Buffer="True" in the Page Directive of the page and not in codebehind.

I just tried this in VS2008 on a Web Site project:

  1. Create new item
  2. Choose "Web page"
  3. Leave all the html-tags in there, just for fun
  4. Fill the page_load like this

    protected void Page_Load(object sender, EventArgs e)  
    {  
      Response.Write("test1");  
      Response.Clear();  
      Response.Write("test2");  
      Response.End();  
    }
    

It will then output "test2" without any html-tags.

like image 163
Espo Avatar answered Nov 11 '22 04:11

Espo