We can also achieve this by disabling browser caching in code behind write the following lines of code in Page_Init event or Page_Load event and don’t forgot to add namespace using System.Web; because HttpCacheability related to that namespace
protected void Page_Init(object sender, EventArgs e)
{
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetExpires(DateTime.Now.AddSeconds(-1));
Response.Cache.SetNoStore();
}
We need to place this code in a page wherever we need to disable browser back button. If we use above caching method to disable browser back button that will display webpage expired message like this
------------------------------ OR ------------------------------------------------
<script type = "text/javascript" >
function preventBack(){window.history.forward();}
setTimeout("preventBack()", 0);
window.onunload=function(){null};
</script>
I have tested the script in the following browsers
1. Internet Explorer 5.55
2. Internet Explorer 6
3. Internet Explorer 7
4. Mozilla Firefox 3
5. Opera 9
6. Safari 4
7. Google Chrome