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 Invoke keypress event in web Application

How to Invoke keypress event in web Application

Scheduled Pinned Locked Moved ASP.NET
csharpjavascripttutorial
15 Posts 4 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.
  • A ais07

    write this code in page load txt.Attributes.Add("onkeypress", "javascript:return DecimalLength(Event)"); and in page source:- function DecimalLength(e) { var KeyChar = (e.which) ? e.which : e.keyCode; if(KeyChar > 57 && KeyChar < 48) { if(window.event) e.returnValue = false; else e.preventDefault(); } } //Check keycode for numbers. Hope this will help you...........

    Life Is Beautiful

    C Offline
    C Offline
    Christian Graus
    wrote on last edited by
    #6

    ais07 wrote:

    if(KeyChar > 57 && KeyChar < 48)

    hmm...... So, if the number is greater than 57 and AT THE SAME TIME is less than 48......

    Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

    A A 2 Replies Last reply
    0
    • C Christian Graus

      ais07 wrote:

      if(KeyChar > 57 && KeyChar < 48)

      hmm...... So, if the number is greater than 57 and AT THE SAME TIME is less than 48......

      Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

      A Offline
      A Offline
      Abhishek Sur
      wrote on last edited by
      #7

      :laugh: :laugh: Silly mistakes....

      Abhishek Sur My Latest Articles Working with Excel using MDAC
      Basics on LINQ and Lambda Expressions
      Create .NET Templates

      C 1 Reply Last reply
      0
      • V vikas shukla

        hi sir, i want to know the keypress event in web application with the language c# for a textbox.textbox should have only integer value.send me javascript also if there is any use of javascript.

        A Offline
        A Offline
        Abhishek Sur
        wrote on last edited by
        #8

        you mean it will postback to the server on each keypress?? :omg: :omg:

        Abhishek Sur My Latest Articles Working with Excel using MDAC
        Basics on LINQ and Lambda Expressions
        Create .NET Templates

        C 1 Reply Last reply
        0
        • A Abhishek Sur

          you mean it will postback to the server on each keypress?? :omg: :omg:

          Abhishek Sur My Latest Articles Working with Excel using MDAC
          Basics on LINQ and Lambda Expressions
          Create .NET Templates

          C Offline
          C Offline
          Christian Graus
          wrote on last edited by
          #9

          He has absolutely no idea about web development, obviously.

          Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

          A 1 Reply Last reply
          0
          • A Abhishek Sur

            :laugh: :laugh: Silly mistakes....

            Abhishek Sur My Latest Articles Working with Excel using MDAC
            Basics on LINQ and Lambda Expressions
            Create .NET Templates

            C Offline
            C Offline
            Christian Graus
            wrote on last edited by
            #10

            Yeah, it's not a big deal, except that the OP is obviously clueless, and would be unable to debug this code.

            Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

            1 Reply Last reply
            0
            • A ais07

              write this code in page load txt.Attributes.Add("onkeypress", "javascript:return DecimalLength(Event)"); and in page source:- function DecimalLength(e) { var KeyChar = (e.which) ? e.which : e.keyCode; if(KeyChar > 57 && KeyChar < 48) { if(window.event) e.returnValue = false; else e.preventDefault(); } } //Check keycode for numbers. Hope this will help you...........

              Life Is Beautiful

              V Offline
              V Offline
              vikas shukla
              wrote on last edited by
              #11

              sir it's not working.can we do this from code behind.

              C 1 Reply Last reply
              0
              • V vikas shukla

                sir it's not working.can we do this from code behind.

                C Offline
                C Offline
                Christian Graus
                wrote on last edited by
                #12

                vikas shukla wrote:

                sir it's not working

                No, for the reason I stated. A number can't be > 57 AND less than 48 at the same time.

                vikas shukla wrote:

                can we do this from code behind.

                I'm sorry, but you may well be too dumb to do this at all. Do you REALLY want your page to reload itself every time someone presses a key ? Thankfully Microsoft realises how retarded that would be, so they don't offer support for it.

                Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

                1 Reply Last reply
                0
                • C Christian Graus

                  He has absolutely no idea about web development, obviously.

                  Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

                  A Offline
                  A Offline
                  Abhishek Sur
                  wrote on last edited by
                  #13

                  yes. I agree. Should read basic books on ASP.NET :) :)

                  Abhishek Sur My Latest Articles Working with Excel using MDAC
                  Basics on LINQ and Lambda Expressions
                  Create .NET Templates

                  1 Reply Last reply
                  0
                  • C Christian Graus

                    ais07 wrote:

                    if(KeyChar > 57 && KeyChar < 48)

                    hmm...... So, if the number is greater than 57 and AT THE SAME TIME is less than 48......

                    Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

                    A Offline
                    A Offline
                    ais07
                    wrote on last edited by
                    #14

                    Sir, This code which I had suggested is only for reference not to copy as it is.

                    Life Is Beautiful

                    C 1 Reply Last reply
                    0
                    • A ais07

                      Sir, This code which I had suggested is only for reference not to copy as it is.

                      Life Is Beautiful

                      C Offline
                      C Offline
                      Christian Graus
                      wrote on last edited by
                      #15

                      Yeah, well, the guy asking you is as dumb as a post, he's going to copy and paste it, and have no idea how to fix it. I know you were just showing the concept, and I've made dumber mistakes, I am not taking a shot at you. I just could see problems brewing because the OP is too dumb to know what this code does, he sure as hell can't debug it.

                      Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

                      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