Home » Applications » Disable Back Button

Disable Back Button

My .aspx Page

<%@ Page Language=”VB” AutoEventWireup=”false” CodeFile=”Page1.aspx.vb” 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”>
<title>Page 1</title>
<script type = “text/javascript” >
function preventBack(){window.history.forward();}
setTimeout(“preventBack()”, 10);
window.onunload=function(){null};
</script>

</head>
<body>
<form id=”form1″ runat=”server”>
<h1>My Page</h1>
<div>
Take me to Google<br />
<asp:Button ID=”Button1″ runat=”server” Text=”Google” />
</div>
</form>
</body>
</html>

Code Behind Page

Partial Class _Default
Inherits System.Web.UI.Page

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Response.Redirect(“http://google.com”)
End Sub

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
End Sub
End Class