Solved

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

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

AJAX ModalPopupExtender has a required property "TargetControlID" which may seem to be very confusing to new users. It means the server control that will be extended by the ModalPopup, for instance, if when you click a button, a ModalPopup displays,…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

743 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now