Key Validation

Discussion in 'ASP .Net' started by Paul Paiva, Oct 14, 2003.

  1. Paul Paiva

    Paul Paiva Guest

    In the VB6 days I was successfully able to validate the keys typed into a
    text box, to allow only numeric keys, or whatever the need was. I would
    simply trap for those values in KeyCode or KeyAscii in the key_down or
    key_press events. When I wanted to disallow a given key, I would set the
    value of KeyCode or KeyAscii to zero.

    In dot net, I'm finding that it is doesn't work quite the same way. I've
    tried a few techniques but no avail. I'm thinking there is some basic
    concept I am missing. If anyone has some basic key validation code that
    would be helpful, or can you point me in the right direction.

    Thanks
    Paul
     
    Paul Paiva, Oct 14, 2003
    #1
    1. Advertising

  2. One way to do this is to handle the KeyPress event on the TextBox. If you
    want to block a character, you can set the "Cancelled" property of the
    KeyPressEventArgs parameter to true. For example, this code would ignore all
    "a"s:

    Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As
    System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress

    If e.KeyChar = "a" Then

    e.Handled = True

    End If

    End Sub


    "Paul Paiva" <> wrote in message
    news:...
    > In the VB6 days I was successfully able to validate the keys typed into a
    > text box, to allow only numeric keys, or whatever the need was. I would
    > simply trap for those values in KeyCode or KeyAscii in the key_down or
    > key_press events. When I wanted to disallow a given key, I would set the
    > value of KeyCode or KeyAscii to zero.
    >
    > In dot net, I'm finding that it is doesn't work quite the same way. I've
    > tried a few techniques but no avail. I'm thinking there is some basic
    > concept I am missing. If anyone has some basic key validation code that
    > would be helpful, or can you point me in the right direction.
    >
    > Thanks
    > Paul
    >
    >
     
    Ed Kaim [MSFT], Oct 14, 2003
    #2
    1. Advertising

  3. Paul Paiva

    Paul Paiva Guest

    Awesome. Works great. Thank!

    "Ed Kaim [MSFT]" <> wrote in message
    news:%...
    > One way to do this is to handle the KeyPress event on the TextBox. If you
    > want to block a character, you can set the "Cancelled" property of the
    > KeyPressEventArgs parameter to true. For example, this code would ignore

    all
    > "a"s:
    >
    > Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As
    > System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
    >
    > If e.KeyChar = "a" Then
    >
    > e.Handled = True
    >
    > End If
    >
    > End Sub
    >
    >
    > "Paul Paiva" <> wrote in message
    > news:...
    > > In the VB6 days I was successfully able to validate the keys typed into

    a
    > > text box, to allow only numeric keys, or whatever the need was. I would
    > > simply trap for those values in KeyCode or KeyAscii in the key_down or
    > > key_press events. When I wanted to disallow a given key, I would set

    the
    > > value of KeyCode or KeyAscii to zero.
    > >
    > > In dot net, I'm finding that it is doesn't work quite the same way.

    I've
    > > tried a few techniques but no avail. I'm thinking there is some basic
    > > concept I am missing. If anyone has some basic key validation code that
    > > would be helpful, or can you point me in the right direction.
    > >
    > > Thanks
    > > Paul
    > >
    > >

    >
    >
     
    Paul Paiva, Oct 15, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Christian Bongiorno

    custom key and hasmap using a ranged key

    Christian Bongiorno, Jun 15, 2004, in forum: Java
    Replies:
    1
    Views:
    471
    Roedy Green
    Jun 15, 2004
  2. Patrick Guio
    Replies:
    6
    Views:
    3,262
    chris
    Oct 20, 2004
  3. shyam
    Replies:
    8
    Views:
    450
    Priscilla Walmsley
    Jun 21, 2006
  4. Florian Lindner

    key - key pairs

    Florian Lindner, Jun 23, 2005, in forum: Python
    Replies:
    8
    Views:
    587
    Paul McGuire
    Jun 24, 2005
  5. M P
    Replies:
    1
    Views:
    540
Loading...

Share This Page