Solved

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

Posted on 2004-08-23
3
238 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
[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 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

730 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