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. handle backspace key

handle backspace key

Scheduled Pinned Locked Moved ASP.NET
csharpasp-nethelp
7 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.
  • H Offline
    H Offline
    hi_everybody
    wrote on last edited by
    #1

    Hi, hi i am new in asp.net. I have problem that at the time of using website if i press backspace key then it shows the previous page, i want to an alert message if user press backspace key at the time using website... thanks

    B 1 Reply Last reply
    0
    • H hi_everybody

      Hi, hi i am new in asp.net. I have problem that at the time of using website if i press backspace key then it shows the previous page, i want to an alert message if user press backspace key at the time using website... thanks

      B Offline
      B Offline
      Brij
      wrote on last edited by
      #2

      Use the following JS function

      function checkBackSpace()
      {
      if(event.keyCode==8)
      {
      alert('You pressed BackSpace');
      return false;
      }
      }

      and put it on body tag as

      Now you will get a message.

      Cheers!! Brij

      P 1 Reply Last reply
      0
      • B Brij

        Use the following JS function

        function checkBackSpace()
        {
        if(event.keyCode==8)
        {
        alert('You pressed BackSpace');
        return false;
        }
        }

        and put it on body tag as

        Now you will get a message.

        Cheers!! Brij

        P Offline
        P Offline
        Prosanta Kundu online
        wrote on last edited by
        #3

        I think Brij is right. But a little changes are required in this code. Otherwise it will alert when user hits backspace key in a textbox. So here is the answer below In JS code --------------------- function checkBackSpace(event) {       event = event || window.event;       var target = event.target || event.srcElement;       if(event.keyCode==8 && (!(target.type =="text" || target.type =="textarea"))       {             alert('You pressed BackSpace');             return false;       }       return true; } and put it on body tag as ------------------------------- <body   onkeydown="return checkBackSpace(event);> Cheers Prosanta

        B 1 Reply Last reply
        0
        • P Prosanta Kundu online

          I think Brij is right. But a little changes are required in this code. Otherwise it will alert when user hits backspace key in a textbox. So here is the answer below In JS code --------------------- function checkBackSpace(event) {       event = event || window.event;       var target = event.target || event.srcElement;       if(event.keyCode==8 && (!(target.type =="text" || target.type =="textarea"))       {             alert('You pressed BackSpace');             return false;       }       return true; } and put it on body tag as ------------------------------- <body   onkeydown="return checkBackSpace(event);> Cheers Prosanta

          B Offline
          B Offline
          Brij
          wrote on last edited by
          #4

          Thanks for your update. :)

          Cheers!! Brij

          H 1 Reply Last reply
          0
          • B Brij

            Thanks for your update. :)

            Cheers!! Brij

            H Offline
            H Offline
            hi_everybody
            wrote on last edited by
            #5

            :) thanks a lot you both Brij and Prosanta...

            H 1 Reply Last reply
            0
            • H hi_everybody

              :) thanks a lot you both Brij and Prosanta...

              H Offline
              H Offline
              hi_everybody
              wrote on last edited by
              #6

              hi its working but there is some error when i navigating using tab key.... it throughs error related object... why? how i handle it?

              P 1 Reply Last reply
              0
              • H hi_everybody

                hi its working but there is some error when i navigating using tab key.... it throughs error related object... why? how i handle it?

                P Offline
                P Offline
                Prosanta Kundu online
                wrote on last edited by
                #7

                Hi here is your code below function checkBackSpace(event) {          event = event || window.event;          var target = event.target || event.srcElement;          if(event.keyCode==8)          {                if((!(target.type =="text" || target.type =="textarea"))                {                      alert('You pressed BackSpace');                      return false;                   }          }          return true; } Cheers Prosanta

                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