home » blogs » vivek_iit » 'Disable' Back Browser Button ASP.NET
posted 12/22/2008 by vivek_iit
The "Back" browser button (or for that matter any other browser button) cannot be actually disabled by a web application as the security context will not allow this (think of what nasty things could happen if web applications can remove buttons from client browsers!)
What we can do is to somehow make sure that browser does not cache the web pages (which will cause the"Back" "Forward" buttons to grey out), and this can be easily done by expiring the Response. The code for this has slightly changed in ASP.NET 2.0 (there is a new HttpCachePolicy class) :
/* * Code disables caching by browser. Hence hitting the back browser button * causes the Page_Load event to fire again. */ Response.Cache.SetCacheability(HttpCacheability.NoCache);Response.Cache.SetExpires(DateTime.Now); //or a date much earlier than current time
In ASP.NET 1.x the code was: Response.CacheControl = "no-cache"; Response.AddHeader("Pragma","no-cache"); Response.Expires = -1;
This will make the browser go to the server everytime the back button is clicked (for that particular page) and prevent any caching of the pages.
vivek_iit (Member since: 11/27/2008) I am one of the administrators at CodeAsp.Net and I love programming, architecting solutions, code reviews, teaching and writing about ASP.NET.
View vivek_iit 's profile
Name: *
Email: (your email is kept secure) *
Website:
Comment (No HTML)
It's fast, easy and free! Submit articles, get your own blog, ask questions & give answers in the forums, and become a better developer, faster.
enter your email address: