Leonardo
Leonardo

Reputation: 11401

Response.Clear not removing anything

If a exception happens, I need to remove the ReportViewer from my page and display a user-friendly + pre-defined message. The problem here is that Response.Clear is doing absolutely nothing!

The result (html and scripts output) is exactly the same, with or without Response.Clear!

I'm calling it in all places, such as Page_Load and Page_Render (before base.Render), etc... at no avail...

How can I "reset" the response and return only my intended message?

Detail: I'm not using MVC!

Upvotes: 1

Views: 1515

Answers (2)

mattfei
mattfei

Reputation: 508

You may consider to put the error message to another page and use TransferRequest to execute that page when the exception happens.

Upvotes: 3

Nikki9696
Nikki9696

Reputation: 6348

Once you've written to the response at all, including headers, clear won't do anything except erase BUFFERED content. It's a stream, and it's started writing to it, so you're stuck after that. Put your exception handling in a better spot - without knowing a lot more about what you're doing, I can't really recommend a specific strategy. We have various levels of error handling for our apps - some server level (500 errors etc), some page level, some client level (javascript). Depends on what happens and when.

Upvotes: 1

Related Questions