************************************************************************************
NOTE: This post has been updated and moved to:
http://www.codeasp.net/blogs/vivek_iit/microsoft.net/19/-disable-back-browser-button-aspnet
Please visit the above link to check the latest version of the post
************************************************************************************
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.