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. Finding the KEYPRESS in ASP.NET with C#

Finding the KEYPRESS in ASP.NET with C#

Scheduled Pinned Locked Moved ASP.NET
csharpasp-nethelptutorialquestion
8 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.
  • J Offline
    J Offline
    John Sundar
    wrote on last edited by
    #1

    currently i m using ASP.NET with C# (.net 2005, 2.0 framework) i have placed a calendar in my webform (calendar from "toolbox --> calendar"). when i press the ESC key, the calendar should get INVISIBLE... how to do this? help me. - KARAN

    E 1 Reply Last reply
    0
    • J John Sundar

      currently i m using ASP.NET with C# (.net 2005, 2.0 framework) i have placed a calendar in my webform (calendar from "toolbox --> calendar"). when i press the ESC key, the calendar should get INVISIBLE... how to do this? help me. - KARAN

      E Offline
      E Offline
      eyeseetee
      wrote on last edited by
      #2

      You could use this and then find the correct key number for esc, i think this one is for when the enter button is pressed if (window.event.keyCode == 13) { calendar.visible - false } hope this helps :)

      J 1 Reply Last reply
      0
      • E eyeseetee

        You could use this and then find the correct key number for esc, i think this one is for when the enter button is pressed if (window.event.keyCode == 13) { calendar.visible - false } hope this helps :)

        J Offline
        J Offline
        John Sundar
        wrote on last edited by
        #3

        i cant get the "window.event.keyCode" and where should i write this code?... where it is?

        D 1 Reply Last reply
        0
        • J John Sundar

          i cant get the "window.event.keyCode" and where should i write this code?... where it is?

          D Offline
          D Offline
          Declan Bright
          wrote on last edited by
          #4

          Hi John Here is an example: Add this script to the head of your page:

          <script type="text/javascript">
          function setCmdKey(event) {
          if (event.keyCode == 27)
          document.getElementById('mydiv').style.visibility = 'hidden';
          }
          </script>

          and add this as a body:

          <body onkeydown="setCmdKey(event);" >
          <div id="mydiv" style="padding:50px;background-color:#f00;">Make me disappear</div>
          </body>

          27 is the keycode for the escape key

          Declan Bright www.declanbright.com

          J 2 Replies Last reply
          0
          • D Declan Bright

            Hi John Here is an example: Add this script to the head of your page:

            <script type="text/javascript">
            function setCmdKey(event) {
            if (event.keyCode == 27)
            document.getElementById('mydiv').style.visibility = 'hidden';
            }
            </script>

            and add this as a body:

            <body onkeydown="setCmdKey(event);" >
            <div id="mydiv" style="padding:50px;background-color:#f00;">Make me disappear</div>
            </body>

            27 is the keycode for the escape key

            Declan Bright www.declanbright.com

            J Offline
            J Offline
            John Sundar
            wrote on last edited by
            #5

            THANKS A LOT MY DEAR!.. i m searching this for long time.. since i thought that we cant handle the SERVER SIDE process (.net calendar) in client side scripting (javascript).. i m not strong in JAVASCRIPT :(

            1 Reply Last reply
            0
            • D Declan Bright

              Hi John Here is an example: Add this script to the head of your page:

              <script type="text/javascript">
              function setCmdKey(event) {
              if (event.keyCode == 27)
              document.getElementById('mydiv').style.visibility = 'hidden';
              }
              </script>

              and add this as a body:

              <body onkeydown="setCmdKey(event);" >
              <div id="mydiv" style="padding:50px;background-color:#f00;">Make me disappear</div>
              </body>

              27 is the keycode for the escape key

              Declan Bright www.declanbright.com

              J Offline
              J Offline
              John Sundar
              wrote on last edited by
              #6

              s my friend. its help me a lot. but the thing is when i use more than one calendar, problem occuring. i.e... function show_key ( the_key ) { if ( ! the_key ) { the_key = event.keyCode; } if(the_key == 27) { document.getElementById("Calendar1").style.visibility="hidden"; document.getElementById("Calendar2").style.visibility="hidden"; document.getElementById("Calendar3").style.visibility="hidden"; } } help me plz......... - KARAN

              D 1 Reply Last reply
              0
              • J John Sundar

                s my friend. its help me a lot. but the thing is when i use more than one calendar, problem occuring. i.e... function show_key ( the_key ) { if ( ! the_key ) { the_key = event.keyCode; } if(the_key == 27) { document.getElementById("Calendar1").style.visibility="hidden"; document.getElementById("Calendar2").style.visibility="hidden"; document.getElementById("Calendar3").style.visibility="hidden"; } } help me plz......... - KARAN

                D Offline
                D Offline
                Declan Bright
                wrote on last edited by
                #7

                Since you haven't described what the problem is I will have to guess. Are the 3 calendar controls on the page when you call the javascript? Have they been written out to the browser?, you need to look at the page source to verify this. My guess is that they are not all there so you will have to test for them in the javascript like this:

                if(the_key == 27)
                {
                if(document.getElementById("Calendar1"))
                document.getElementById("Calendar1").style.visibility="hidden";
                if(document.getElementById("Calendar2"))
                document.getElementById("Calendar2").style.visibility="hidden";
                if(document.getElementById("Calendar3"))
                document.getElementById("Calendar3").style.visibility="hidden";
                }

                Declan Bright www.declanbright.com

                J 1 Reply Last reply
                0
                • D Declan Bright

                  Since you haven't described what the problem is I will have to guess. Are the 3 calendar controls on the page when you call the javascript? Have they been written out to the browser?, you need to look at the page source to verify this. My guess is that they are not all there so you will have to test for them in the javascript like this:

                  if(the_key == 27)
                  {
                  if(document.getElementById("Calendar1"))
                  document.getElementById("Calendar1").style.visibility="hidden";
                  if(document.getElementById("Calendar2"))
                  document.getElementById("Calendar2").style.visibility="hidden";
                  if(document.getElementById("Calendar3"))
                  document.getElementById("Calendar3").style.visibility="hidden";
                  }

                  Declan Bright www.declanbright.com

                  J Offline
                  J Offline
                  John Sundar
                  wrote on last edited by
                  #8

                  thanks bright :-D

                  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