Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Display custom error page

Status
Not open for further replies.

Muddmuse

Programmer
Jul 31, 2001
85
US
All my aspx pages are overridden with my own BasePage class. It handles logging and display of errors, among other things. I've also implemented a page template approach using custom controls that contain nested controls to paint header, menus, footer etc. The BasePage class has properties to track the display state of the page - for example, which menus to display.

What I'm currently doing in BasePage when errors occur is this:
StringWriter writer = new StringWriter();
Server.Execute("error.aspx", writer);
Response.Clear();
Response.Write(writer.ToString());
Server.ClearError();

This works fine but what I really want to do is maintain the state of the page (ie: which menus were painted when the error occurred) so the user does not lose thier current navigation.

Since I'm doing a Server.Execute the context is the same so I have all the exception information but if my error aspx page contains the same template structure as the aspx page that generated the error I get further errors about multiple controls with the same id. I think what I want to do is replace the content of my custom control in my template with the error information but am not sure how to do that.

Redirecting doesn't seem feesible because I'd lose the exception info (unless I pass stuff on the querystring).

Any ideas or other approaches?
 
if you do use a redirect you could save the exception to a session variable.

Jason Meckley
Database Analyst
WITF
 
I thought of that but being fairly new to .net figured that there must be a better solution. The thing I don't understand about my code above is that since I'm doing a response.clear why would I be getting run time errors about loading controls in my error page with the same id as controls in the page that threw the exception? What exactly does response.clear do/not do?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top