|
Here's the sample code that works
-----------------------------------------------------
I tried many many many things on different websites. It never worked. Finally I wrote this code which works,
Here's how it works. you need to greate a dummy page say "somepage.aspx" this page has no content only a redirect.
This is the code below that worked for me. please not somepage.aspx canoot have any other functionality other then
just preventing backbutton press.
SomePage.aspx.vb
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Response.Cache.SetCacheability(HttpCacheability.NoCache)
End Sub
SomePage.aspx
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<script type="text/javascript">
function noBack(){window.history.forward();}
noBack();
window.onload=noBack;
window.onpageshow=function(evt){if(evt.persisted)noBack();}
window.onunload=function(){void(0);}
function delayer(){
window.location = "Default.aspx"
}
</script>
<body onLoad="setTimeout('delayer()', 500)">
<form id="form1" runat="server">
<div>
</div>
</form>
</body>
</html>
I want to disable the browser back button when the LOGOUT operation is performed
in my .aspx page by the user.For this i have replaced the body tag as
<body onload="if(history.length>0) history.go(+1)"<
it can also be acheived using the
window.history.forward(1);
it is working good for me ,but still i have a problem.
As i have set the logout operation in a master page the browser back nutton is disabled
for every page associated with the master page.It is because the body tag onload command
is executed for ever page associated with the master page.
I only need to execute the onload operation only when the logoout is performed.
I have tried to replace the body tag onload in the logout operation.
In my logout button click i have written the following code
Protected Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Session.Clear()
Session.Abandon()
Session("User") = 0
Response.Cache.SetCacheability(HttpCacheability.NoCache)
Response.Cache.SetExpires(DateTime.MinValue)
Dim mybodytag As HtmlGenericControl
mybodytag = Page.Master.FindControl("Master")
mybodytag.Attributes.Add("onload", "window.history.forward(1);")
mybodytag.Attributes.Add("onunload", "window.history.forward(1);")
Response.Redirect("Frmliblogin.aspx")
End Sub
I have tried it for both onload an unload operations.
But it doesn't work for me.
If you kow the answer or any other alternative solutions
pls solve it.
|