Friday 18 October 2013

ASP.NET-Disabling Back Button of Browser in Javascript

 Hi friends, in this article I will explain about  ASP.NET-Disabling Back Button of Browser in Javascript
I already explained in the previous articles about ASP.NET - Disabling Back Button of Browser in C#/VB.NETDetecting sequence of at least 3 sequential numbers from a given List in ASP.NET using JavaScript and HTML - How can I open multiple links/windows with a single anchor tag using Javascript

In ASP.NET:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title >ASP.NET-Disabling Back Button of Browser in Javascript</title>
<script type="text/javascript" language="javascript">
    function DisableBrowserBackButton() {
        window.history.forward()
    }
    DisableBrowserBackButton();
    window.onload = DisableBrowserBackButton;
    window.onpageshow = function (evt) { if (evt.persisted) DisableBrowserBackButton() }
    window.onunload = function () { void (0) }
</script>
</head>
 <body>
<form  runat ="server">
   User Name: <asp:TextBox runat ="server" ID="txtUser"></asp:TextBox> 
 <asp:Button runat ="server" ID="Button1" Text="Go" PostBackUrl ="~/NoBack.aspx"  />
    </form>
</body>
</html>


The output of the above code as shown in the below figure.
When we click on Back button in the browser then it shows as shown in the below figure.


No comments:

Post a Comment

© 2012-2018 Aspdotnet-Kishore.blogspot.com. All Rights Reserved.
The content is copyrighted to Kishore and may not be reproduced on other websites without permission from the owner.