Disabling/Forcing to some other page when the user hits Browser Back Button RRS feed

  • Question

  • I have an asp.net online Payment site. In that we have a page where it has Request.Form to get the response from Payment Processing API and if the payment is succesfull it insertsthe succesfull payment into database and redirects the user to next page where it shows the success message. When the User Hits the back button on this success page it is going to the previous page where it is saving the payment into databse duplicate times.

    Is there any way we can disable the browser back button or force it to go to some other page.

    I have tried window.history.forward() but not working for me.

    • Moved by CoolDadTx Friday, April 5, 2019 7:41 PM ASP.NET related
    Friday, April 5, 2019 5:30 PM

All replies

  • Hello,

    There are always ways to defeat the back button. If you use this which we used at one time and worked until a user right clicks the back button to get history and navigate backwards.

        $(document).ready(function () {
            history.pushState(null, null, document.URL);
            window.addEventListener('popstate', function () {
                history.pushState(null, null, document.URL);

    Rather then attempting to stop them from going back consider using logic sets a value when a page has been done and then if they try to go back detect this and handle it.

    Or try this


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    profile for Karen Payne on Stack Exchange

    Friday, April 5, 2019 5:43 PM
  • Please post questions related to ASP.NET in the ASP.NET forums.

    Michael Taylor http://www.michaeltaylorp3.net

    Friday, April 5, 2019 7:41 PM