Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. How to Disable back button

How to Disable back button

Scheduled Pinned Locked Moved ASP.NET
javascripttoolstutorial
9 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Samarjeet Singh india
    wrote on last edited by
    #1

    Hi All, In my application user filter,serch items in the gridview but when he/she click the button then all item serched items he losed. I want to disable back button.for this I m using following code <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)} </script> but it breaks for go to previous page but in this situation user is in same page. thnks to all.........

    J 1 Reply Last reply
    0
    • S Samarjeet Singh india

      Hi All, In my application user filter,serch items in the gridview but when he/she click the button then all item serched items he losed. I want to disable back button.for this I m using following code <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)} </script> but it breaks for go to previous page but in this situation user is in same page. thnks to all.........

      J Offline
      J Offline
      Jain Vijay
      wrote on last edited by
      #2

      As I think, the best way to disable the back button is "don't create the history of the page". Because may be in some browser's, disable code will not work. Here is the code to remove the history of a particular page:- <% Response.Expires = 0 Response.ExpiresAbsolute = DateTime.Now.AddDays(-1) Response.AddHeader("cache-control", "private") Response.CacheControl = "no-cache" %> Hope this will help you......

      Regards... Vijay Jain :)

      "One thing you can't recycle is wasted time."

      A S 2 Replies Last reply
      0
      • J Jain Vijay

        As I think, the best way to disable the back button is "don't create the history of the page". Because may be in some browser's, disable code will not work. Here is the code to remove the history of a particular page:- <% Response.Expires = 0 Response.ExpiresAbsolute = DateTime.Now.AddDays(-1) Response.AddHeader("cache-control", "private") Response.CacheControl = "no-cache" %> Hope this will help you......

        Regards... Vijay Jain :)

        "One thing you can't recycle is wasted time."

        A Offline
        A Offline
        awedaonline
        wrote on last edited by
        #3

        What part/tag of the .aspx page or (event handler) code behind does this code fits?

        J 1 Reply Last reply
        0
        • A awedaonline

          What part/tag of the .aspx page or (event handler) code behind does this code fits?

          J Offline
          J Offline
          Jain Vijay
          wrote on last edited by
          #4

          you can put this code on above the HTML tag of your .aspx page.

          Regards... Vijay Jain :)

          "One thing you can't recycle is wasted time."

          A 1 Reply Last reply
          0
          • J Jain Vijay

            you can put this code on above the HTML tag of your .aspx page.

            Regards... Vijay Jain :)

            "One thing you can't recycle is wasted time."

            A Offline
            A Offline
            awedaonline
            wrote on last edited by
            #5

            Thanks for your reply.

            J 1 Reply Last reply
            0
            • J Jain Vijay

              As I think, the best way to disable the back button is "don't create the history of the page". Because may be in some browser's, disable code will not work. Here is the code to remove the history of a particular page:- <% Response.Expires = 0 Response.ExpiresAbsolute = DateTime.Now.AddDays(-1) Response.AddHeader("cache-control", "private") Response.CacheControl = "no-cache" %> Hope this will help you......

              Regards... Vijay Jain :)

              "One thing you can't recycle is wasted time."

              S Offline
              S Offline
              Samarjeet Singh india
              wrote on last edited by
              #6

              Thnks For Reply I have used this code but it is going to back...... in all browsers(IE,Mozila)

              J 1 Reply Last reply
              0
              • S Samarjeet Singh india

                Thnks For Reply I have used this code but it is going to back...... in all browsers(IE,Mozila)

                J Offline
                J Offline
                Jain Vijay
                wrote on last edited by
                #7

                This code has to be used on previous page. Means, if you want's to disable the "back" button of page "zxc.aspx", so you have to put this code in previous page of "zxc.aspx", from which you have come to "zxc.aspx". i.e. if you have come from "test.aspx" (on click of any link) to "zxc.aspx", then you have to put this code on "test.aspx" page. Try this. This will definitely work in all browsers.

                Regards... Vijay Jain :)

                "One thing you can't recycle is wasted time."

                S 1 Reply Last reply
                0
                • J Jain Vijay

                  This code has to be used on previous page. Means, if you want's to disable the "back" button of page "zxc.aspx", so you have to put this code in previous page of "zxc.aspx", from which you have come to "zxc.aspx". i.e. if you have come from "test.aspx" (on click of any link) to "zxc.aspx", then you have to put this code on "test.aspx" page. Try this. This will definitely work in all browsers.

                  Regards... Vijay Jain :)

                  "One thing you can't recycle is wasted time."

                  S Offline
                  S Offline
                  Samarjeet Singh india
                  wrote on last edited by
                  #8

                  Thnks Dear, In my application user is always in same page.because he is filtering,sorting and serching items in grid then grid is showing data according to filtering,sorting and serching but it open in same page always not in other page...... Thnks....

                  1 Reply Last reply
                  0
                  • A awedaonline

                    Thanks for your reply.

                    J Offline
                    J Offline
                    Jain Vijay
                    wrote on last edited by
                    #9

                    Your welcome

                    Regards... Vijay Jain :)

                    "One thing you can't recycle is wasted time."

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups