Try this code:
<script type="text/javascript" language="javascript">
window.history.forward(1);
document.attachEvent("onkeydown", my_onkeydown_handler);
function my_onkeydown_handler()
{
switch (event.keyCode)
{
case 116 :
event.returnValue = false;
event.keyCode = 0;
window.status = "We have disabled F5";
break;
}
}
</script>
and use this one in code behind
Session.Clear();
Session.Abandon();
Alternative:
On code behind write:
protected void Page_Load(object sender, EventArgs e)
{
HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
HttpContext.Current.Response.Cache.SetNoServerCaching();
HttpContext.Current.Response.Cache.SetNoStore();
}
..and on client side same JavaScript like above:
<script type="text/javascript" language="javascript">
window.history.forward(1);
document.attachEvent("onkeydown", my_onkeydown_handler);
function my_onkeydown_handler()
{
switch (event.keyCode)
{
case 116 : // F5;
event.returnValue = false;
event.keyCode = 0;
window.status = "We have disabled F5";
break;
}
}
</script>
Also have a look at following links :
1.
Three ways to disable browser back button[
^]
2.
Use Javascript to restrict user from pressing back button in browser[
^]
3.
A Thorough examination of browser back button[
^]
4.
Simple solution[
^]
Note: Many of the experts suggest not to disable expected browser behaviour. Instead make your pages handle the possibility of users going back. In other words redirect the user to certain page when user tries to press back button.