?
Solved

Prevent Form Data Loss in ASP.NET on Application Error

Posted on 2003-03-12
3
Medium Priority
?
289 Views
Last Modified: 2010-05-18
Hi.

I was wondering what is the best (and most secure) way to prevent a user from losing all of their entered form data if an application error (unhandled exception) occurs when they submit the form on an ASP.Net page.  I try to handle errors as much as possible in the page, but sometimes there are a few bugs I didn't catch or a server error outside my control.  I am using custom error pages, and if an unhandled exception occurs, the user loses all data entered on a form (even if they use the browsers back button).

Thanks.
0
Comment
Question by:DJDoug
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 23

Accepted Solution

by:
naveenkohli earned 600 total points
ID: 8121268
If there is an exception thrown from your page, then there is no way to retrieve the data from error page. What you can do is... before you do any thing with the data, store every piece of data in Session at the load time. And when you are done with processing, in pre render get rid of all data in session (for that page). You may have to make use of state engine for session or external DB support because exception may end up cleaning up your session. And if user comes back and the session was not cleared in PreRender that means he ran into some trouble and load the information from stored session.
0
 
LVL 4

Author Comment

by:DJDoug
ID: 8128988
If I am understanding correctly:

OnLoad --> Store Data in Session using state engine or external DB support.
OnPreRender --> Clear session.

So, on the OnLoad event, I would first check to see if the session had been cleared before storing the data.  If it had not been cleared, then I would load the data from the Session.

OK, what happens if the User closes the browser?  (Such as in the case the error is not immediately fixed.  Some forms are quite long.)  Could I apply this same concept by writing to an encrypted cookie?  Or, if the web form is for an authenticated user, I guess I could write to a temp db based on the user?

I'll increase the points for a good code sample (prefer VB.Net) or article.
0
 
LVL 23

Expert Comment

by:naveenkohli
ID: 8129119
The same concept should still work...
If user is moving from page to page on your system, then you can add logic to each page and making sure that it first clears the previous session variables and then starting the new save.
If you use Response.Redirect to go to new page, then catch ThreadAbortException throw by Redirect method. This exception is not an error. It is framework's way of indicating that it is aborting the current thread.

So if user closed the browser, that means they never wen to next page. So state will exist in DB (session). So you can load it when they come back.
0

Featured Post

Is Your Team Achieving Their Full Potential?

74% of employees feel they are not achieving their full potential. With Linux Academy, not only will you strengthen your team's core competencies but also their knowledge of of the newest IT topics.

With new material every week, we'll make sure that you stay ahead of the game.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question