Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / January 2008

Tip: Looking for answers? Try searching our database.

Response.Clear() doesn't clear

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
David - 31 Jan 2008 17:58 GMT
When I use Response.Clear() it doesn't seem to have an effect. The original
aspx page code remains. I have tried creating test projects in both VS 2005 &
2008, where I just add a new aspx page and place in the Page_Load() event
Response.Clear(), but nothing is cleared out. I have tried various ways to
get the page to clear, including the code below:

protected void Page_Load(object sender, EventArgs e)
{
    Response.ContentType = "text/html";
    Response.Clear();
    Response.BufferOutput = true;
    Response.Write("<html><body>Testing</body></html>");
    Response.Flush();
}

The page will have the <html><body>Testing</body></html> at the top of the
page's code file, but all of the original default aspx code will still be
there also. I have tried this with both ASP .NET 2.0 & 3.5 in VS 2008. I have
looked at a lot of examples on the Internet and have not seen anything else
mentioned that is necessary. Is there something else that I am missing?
Milosz Skalecki [MCAD] - 31 Jan 2008 19:24 GMT
At this stage of the page's lifecycle internal buffer with the HTML is empty,
it is filled in Render method. In order to make it work you'd have to call
Response.End();

protected void Page_Load(object sender, EventArgs e)
{
    Response.ContentType = "text/html";
    Response.Clear();
    Response.BufferOutput = true;
    Response.Write("<html><body>Testing</body></html>");
    Response.End();
}

Signature

Milosz

> When I use Response.Clear() it doesn't seem to have an effect. The original
> aspx page code remains. I have tried creating test projects in both VS 2005 &
[quoted text clipped - 16 lines]
> looked at a lot of examples on the Internet and have not seen anything else
> mentioned that is necessary. Is there something else that I am missing?
Mark Fitzpatrick - 31 Jan 2008 20:32 GMT
I also find it most useful to set the Buffer in the page directive and note
in the codebehind. This way you don't have to worry about the timing of
things as it's possible to set the buffer too late in the event cycle.

Signature

Hope this helps,
Mark Fitzpatrick
Microsoft MVP - Expression

> When I use Response.Clear() it doesn't seem to have an effect. The
> original
[quoted text clipped - 20 lines]
> else
> mentioned that is necessary. Is there something else that I am missing?

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.