Background
Sometimes their is a need to disable the back button of the browser for security reasons so as to prevent the user from navigating between the pages by using the browser arrow buttons.
Problem
Suppose their is a Login page, when i login into the application, the page will be redirected to the page where I perform all my tasks, after doing all my work, I will logout from the application and the page again will get redirected to the Login page, at that time when i will click on the browser next arrow button it will allow me to show the next page that i have earlier used to Login without the need of new login; so to avoid this problem we need to disable the browser button.
Now let us see how to do it...
open VS --create New Web site-add two web page...
After adding the two web pages, write the following javascript code.
- <script type ="text/javascript">
- window.onload = window.history.forward(0); //calling function on window onload
- </script>
First.aspx Page
- <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head runat="server">
- <script type ="text/javascript">
- windowwindow.onload = window.history.forward(0);
- </script>
- <title></title>
- </head>
- <body bgcolor="silver">
- <form id="form1" runat="server">
- <h4>This is First Page</h4>
- <br /><br /><br />
- <div>
- <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Goto Second Page" />
- </div>
- </form>
- </body>
- </html>


شبير البلوشيPosted Apr 2, 2018, 2:43 AM
What if i don't want to use javascript for this because it's about the security. is there any other way i can implement the same without using javascript?
Vijay GuptaPosted Dec 29, 2017, 9:40 AM
This is not working in visual studio 2010 plz, any any tell how can work this
kiran kumarPosted May 19, 2016, 3:12 AM
Thanks for Sharing,like this how to disable browser refresh button please help me ....
hamida khanamPosted Feb 10, 2014, 12:34 PM
thanks for sharing
Praneet NadkarPosted Jan 22, 2014, 1:35 AM
How about history.go(1); ?
Vithal WadjePosted Jan 13, 2014, 10:03 AM
thanks Priti Kumari mdm
Priti KumariPosted Jan 13, 2014, 1:45 AM
nice blog..........................................
atul chauhanPosted Jan 13, 2014, 1:15 AM
great code