Solved

force a page load on browser back button in c#

Posted on 2012-03-10
3
674 Views
Last Modified: 2012-03-11
I have a webpage http://www.practicelifeintheuktest.co.uk/life-in-the-uk-free-sample-test.aspx  for a quiz test. When user finishes the test and goes to result page and clicks on the browser back button. The page_load event does not fire and session variables which are set in page load are not set and the page does not behave correctly. How can we force page load when user clicks the back button. I have tried a couple of possible solutions like setting the no cache properties but it does not seem to work on this case.

Response.Buffer = true;
Response.ExpiresAbsolute = DateTime.Now.AddDays( - 1);
Response.Expires = 0;
Response.CacheControl = "no-cache";

and

Response.Cache.SetCacheability(HttpCacheability.NoCache);
0
Comment
Question by:mmalik15
  • 2
3 Comments
 
LVL 83

Accepted Solution

by:
Dave Baldwin earned 500 total points
ID: 37705398
Unless you are using javascript/AJAX to load the page, clicking on 'Back' does not contact the server, it just displays from the history cache in the browser which is not the same as checking 'cache' when a new link is clicked.  All the things you listed above are only run on the server and never seen when 'Back' is clicked.
0
 

Author Comment

by:mmalik15
ID: 37705459
thanks for the comment but any suggestion how to handle the back button in this case
0
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 37705481
You can't 'handle' the back button from the server because the server isn't involved.  Only if you do your page load with javascript / AJAX can you reload anything from the server.

What happens if you refresh the page after clicking on 'Back'?
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

825 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