Click here to Skip to main content
15,884,298 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi All,

I want to enable or disable back button as per session based can u guide or send snippets
Posted

One cannot disable the browser back button functionality only thing that can be done is prevent them.

Below JavaScript code needs to be placed in the head section of the page where you don’t want the user to revisit using the back button:
XML
<script>
  function preventBack(){window.history.forward();}
  setTimeout("preventBack()", 0);
  window.onunload=function(){null};
</script>

Suppose there are two pages Page1.aspx and Page2.aspx and Page1.aspx redirects to Page2.aspx.

Hence to prevent user from visiting Page1.aspx using Back Button you will need to place the above script in the head section of Page1.aspx.

For more reference visit : Disable Browser Back Button Functionality using JavaScript
 
Share this answer
 
v2
Browser back button can not be disabled, if you try some alternate solution using java script then it is not guaranteed to work on all the browsers. I will suggest to check the session for null value in Page_Load event for each page and accordingly redirect to the login page if found session value null.
It will not stop the back button but it can prevent any invalid postback to the server.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900