Solved

CustomValidator doesn't remember it's state after browser back button

Posted on 2004-08-23
3
236 Views
Last Modified: 2010-05-18
Hello,

I have an aspx page. On this page the user can make a few selections. When I hit the 'Continue' button I am validating his selections (database access). When the validation fails I set (server-side) : myValidator.IsValid = false;
The page reloads and the validator shows the error message. So far so good.

When I correct the mistake and hit the 'Continue' button, a second page loads. But before the page loads, I set : myValidator.IsValid = true;
I -SEE- the validator disappear from the page before the second page loads, which is ok. But when I click on the back button of the browser (after the second page has loaded), the validator is visible again! Even though I did IsValid = true

It looks like the application is ignoring the IsValid = true. How can I make sure the validator remains invisible?
0
Comment
Question by:JasperB
  • 2
3 Comments
 
LVL 8

Expert Comment

by:shovavnik
ID: 11870488
Initilalize it to IsValid = true in your Page_Load event.  You may have to set the cache expiration to force the page to load from the server in addition.

I'm guessing that when you hit back on your browser, it reloads the previous state of the page before it was posted.

That is, it looks like the following is happening (I could be wrong):

1. User clicks Continue.
2. PostBack - IsValid = false.
3. Page is sent back to the client.
4. User clicks Continue.
5. PostBack - IsValid = true.
6. Redirection (either by Execute or Redirect).
7. New Page is sent to the client.
8. User hits back.
9. The browser is only familiar with the page before it was validated, so it shows the invalid page it saw in step 3.
0
 

Author Comment

by:JasperB
ID: 11870654
I think you are right with the 9 steps you mentioned. Question is: Why doesn't it remember the state in step 5?

I tried to set the expiration to 0 and no caching but when I press the back button of the browser I get the message that the page is expired (but I want to load it automatically) and when I refresh the validator is also visible again.

So the best would be to remember the state of the page.
It that's not possible I could reload the page after the back button. And in that case: How can I make it reload automatically, instead of displaying that I have to refresh manually?
0
 
LVL 8

Accepted Solution

by:
shovavnik earned 250 total points
ID: 11870904
It doesn't remember step 5 because step 5 never gets to the client.

That is, step occurrs on the server and because the page is validated, step 6 redirects to another page.  Regardless of the type of redirection, as long as its server-side redirection, the browser never gets an opportunity to cache the results of the validated page because it's never sent to the browser.

You have several options (not in any particular order):
1. Do the redirection on the client.  That is, do not redirect on the server-side.  Use a javascript function to redirect on the document's onLoad() event.
2. Don't support the browser's back button.  This is probably not feasible for an internet application, but for an intranet application it might be a good solution.  Instead of a back button, provide your own navigation buttons which will redirect to your page to give the user a way to go "Back".
3. Store the state in the session.  This is a bit problematic, because you usually don't want to load the session state if the page has not posted back, which is what you want to do here, so you'll have to be careful about the logic flow.
4. Use the Cache object.  I haven't used it much or read up on it yet, but it should be able to do what you want.  If I'm not mistaken, you'd save the page validation state to the cache the same way you would to the session or the viewstate, except that you can set expiration for the specific cache.  Lookup on this page Caching page output and also caching portions of a page.
http://support.microsoft.com/default.aspx?scid=kb;en-us;307225
5. If you can merge the two pages (reasonably) then you can avoid this problem to begin with.

If I think of other options, I'll post.
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Class Library Dynamics For Connectstring Information 2 28
Angular JS Route 3 68
Save ms data to server side. 19 42
RLDC Reporting in Visual studio 11 13
I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

806 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