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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. C# Browser Back Button recognition.

C# Browser Back Button recognition.

Scheduled Pinned Locked Moved C#
databasecsharphelp
10 Posts 5 Posters 1 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.
  • I Offline
    I Offline
    imnotso
    wrote on last edited by
    #1

    On page load in my web project I do processing and database record writing depending on which page was last and how the user has got there. It has dawned on my that I have forgotten about the browser back button...this is now causing my navigation nightmares. Can I tell if the page was arrived at via the browser back button in my C# code behind. If so I don't want to write any DB records. Simple really.... if browser.control = back { then nothing... } I can bet my last Euro that it is not going to be simple at all... Any help very welcome..

    L G T N 4 Replies Last reply
    0
    • I imnotso

      On page load in my web project I do processing and database record writing depending on which page was last and how the user has got there. It has dawned on my that I have forgotten about the browser back button...this is now causing my navigation nightmares. Can I tell if the page was arrived at via the browser back button in my C# code behind. If so I don't want to write any DB records. Simple really.... if browser.control = back { then nothing... } I can bet my last Euro that it is not going to be simple at all... Any help very welcome..

      L Offline
      L Offline
      leppie
      wrote on last edited by
      #2

      Welcome to web development... The best way to make the page not cachable, and hence it will be loaded every time it is accessed, even with the back button.

      xacc.ide - now with TabsToSpaces support
      IronScheme - 1.0 alpha 3 out now

      I 1 Reply Last reply
      0
      • L leppie

        Welcome to web development... The best way to make the page not cachable, and hence it will be loaded every time it is accessed, even with the back button.

        xacc.ide - now with TabsToSpaces support
        IronScheme - 1.0 alpha 3 out now

        I Offline
        I Offline
        imnotso
        wrote on last edited by
        #3

        Hi, page load does work everytime but the processing inside needs to be conditional on if the page was assessed using the browser back button...I was wondering if I can tell via C#?

        L 1 Reply Last reply
        0
        • I imnotso

          Hi, page load does work everytime but the processing inside needs to be conditional on if the page was assessed using the browser back button...I was wondering if I can tell via C#?

          L Offline
          L Offline
          leppie
          wrote on last edited by
          #4

          Maybe check the referrer field?

          xacc.ide - now with TabsToSpaces support
          IronScheme - 1.0 alpha 3 out now

          I 1 Reply Last reply
          0
          • L leppie

            Maybe check the referrer field?

            xacc.ide - now with TabsToSpaces support
            IronScheme - 1.0 alpha 3 out now

            I Offline
            I Offline
            imnotso
            wrote on last edited by
            #5

            The refferer field?? Is this in the URL?

            1 Reply Last reply
            0
            • I imnotso

              On page load in my web project I do processing and database record writing depending on which page was last and how the user has got there. It has dawned on my that I have forgotten about the browser back button...this is now causing my navigation nightmares. Can I tell if the page was arrived at via the browser back button in my C# code behind. If so I don't want to write any DB records. Simple really.... if browser.control = back { then nothing... } I can bet my last Euro that it is not going to be simple at all... Any help very welcome..

              G Offline
              G Offline
              GuyThiebaut
              wrote on last edited by
              #6

              I am no expert in this area... however I know our web page designer had similar problems. I could make one suggestion which is if you can keep track of the previous page then if you return to that page there is a chance the back button was pressed - although the user could have navigated there via a link as well I guess... Oh well as I said I am no expert...

              Continuous effort - not strength or intelligence - is the key to unlocking our potential.(Winston Churchill)
              I 1 Reply Last reply
              0
              • G GuyThiebaut

                I am no expert in this area... however I know our web page designer had similar problems. I could make one suggestion which is if you can keep track of the previous page then if you return to that page there is a chance the back button was pressed - although the user could have navigated there via a link as well I guess... Oh well as I said I am no expert...

                Continuous effort - not strength or intelligence - is the key to unlocking our potential.(Winston Churchill)
                I Offline
                I Offline
                imnotso
                wrote on last edited by
                #7

                Yes, thats the problem, I'm navigating round the site but need to know if I got there via a browser back button.

                1 Reply Last reply
                0
                • I imnotso

                  On page load in my web project I do processing and database record writing depending on which page was last and how the user has got there. It has dawned on my that I have forgotten about the browser back button...this is now causing my navigation nightmares. Can I tell if the page was arrived at via the browser back button in my C# code behind. If so I don't want to write any DB records. Simple really.... if browser.control = back { then nothing... } I can bet my last Euro that it is not going to be simple at all... Any help very welcome..

                  T Offline
                  T Offline
                  The Nightcoder
                  wrote on last edited by
                  #8

                  One way of ensuring that the form isn't handled more than once (an order form for example) is: 1. On the page that renders the form for the user to fill in: Set a session variable (named so that it doesn't conflict with other forms/pages) to 1. 2. On the page accepting the post (may be the same page, but method=POST): If the session variable isn't 1, reject the post (show an error message or do something completely different). Otherwise, if the form data is valid and processing succeeds, set the variable to 2. If not, display the form again (again setting the variable to 1), preferably amended with an error message. This way you won't accept the same form twice. If you don't want to use session variables (if you're on a server farm, for example), use your database instead. For example, create a row with a unique key (Guid/uniqueidentifier is good, but if security is important, add a signature) when the form is first created and include the key (and the signature if you have one) in the form as a hidden field. You then track transaction progress with another field in the record. This can be elaborated to cater for multi-step transactions as well (including call-backs from, say, credit card payment servers) - but this should give you the general principle. Remember that you should also handle the case when someone jumps right into the middle of your app - and that this may very well be a hacker, faking the entire form contents, the referer field and pretty much everything else (hence the signature idea). And like another poster noted - welcome to the world of web development - statelessness sucks!

                  Peter the small turnip (1) It Has To Work. --RFC 1925[^]

                  1 Reply Last reply
                  0
                  • I imnotso

                    On page load in my web project I do processing and database record writing depending on which page was last and how the user has got there. It has dawned on my that I have forgotten about the browser back button...this is now causing my navigation nightmares. Can I tell if the page was arrived at via the browser back button in my C# code behind. If so I don't want to write any DB records. Simple really.... if browser.control = back { then nothing... } I can bet my last Euro that it is not going to be simple at all... Any help very welcome..

                    N Offline
                    N Offline
                    neelchauhan
                    wrote on last edited by
                    #9

                    Try using the source code from Inter.NET. Inter.NET's Internet Location is http://neelchauhan.my5gb.com/idnx.html.

                    I 1 Reply Last reply
                    0
                    • N neelchauhan

                      Try using the source code from Inter.NET. Inter.NET's Internet Location is http://neelchauhan.my5gb.com/idnx.html.

                      I Offline
                      I Offline
                      imnotso
                      wrote on last edited by
                      #10

                      Not sure how that would help but thanks for the post.....

                      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