Home > Code > Javascript > Disable browser back button using Javascript in ASP.NET

Disable browser back button using Javascript in ASP.NET

by Narain Siddharth   on Dec 15, 2011   Category: Javascript   |  Views: 8848    |  Points: 25   |  Silver 

The below sample javascript code used to disable the browser back button in the asp.net applications. so that we can restrict the user to go back by pressing the browser back button. Include the below code in the Master page

<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Site1.master.cs" Inherits="WebApplication1.Site1" %>

<!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">
function DisableBack() {

window.onload = DisableBack;

window.onpageshow = function(evt) {
if (evt.persisted) DisableBack();
window.onunload = function() { void (0); }


<asp:ContentPlaceHolder ID="head" runat="server">
<form id="form1" runat="server">
<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">

Post Code  |  Code Snippet Home

User Responses

No response found, be the first to review this code snippet.

Submit feedback about this code snippet

Please sign in to post feedback

Latest Posts