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

    How prevent user/disable browser back event in

    down vote
    I am using 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.

    function preventBack(){window.history.forward();}
    setTimeout("preventBack()", 0);
    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.onload = DisableBackButton;
    window.onpageshow = function(evt) { if (evt.persisted) DisableBackButton() }
    window.onunload = function() { void (0) }
    you should place JavaScript code in login page of content placeholder and try it will work for you

    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