You must Sign In to post a response.
  • Category: ASP.NET

    How prevent user/disable browser back event in asp.net

    0
    down vote
    favorite
    I am using asp.net C#.I have created one content page.I don't want user to go back using browser back button.I came to know that it can be done using javascript.Below is my code.

    <script>
    function preventBack(){window.history.forward();}
    setTimeout("preventBack()", 0);
    window.onunload=function(){null};
    </script>
    But I am using content page not normal webpage.My page don't have body tag.I want to disable back button only for this page not entire web site.How to do that?
  • #765353
    Use below code
    <script type="text/javascript" language="javascript">
    function DisableBackButton() {
    window.history.forward()
    }
    DisableBackButton();
    window.onload = DisableBackButton;
    window.onpageshow = function(evt) { if (evt.persisted) DisableBackButton() }
    window.onunload = function() { void (0) }
    </script>
    you should place JavaScript code in login page of content placeholder and try it will work for you

    Thanks
    Koolprasd2003
    Editor, DotNetSpider MVM
    Microsoft MVP 2014 [ASP.NET/IIS]

  • #765358
    Thanks prasad for ur help.I have lot of page in my website including login..from page1 user redirect to page2.


Sign In to post your comments