Results 1 to 3 of 3

Thread: Keypress event in ASP.NET

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Mar 2004
    Posts
    19

    Keypress event in ASP.NET

    In VB this is my code on having only numeric input on the textbox.

    Private Sub txtbox_KeyPress(Index As Integer, KeyAscii As Integer)
    If Index = 5 Or Index = 6 Or Index = 7 Then
    Select Case KeyAscii
    Case vbKey0 To vbKey9
    Case vbKeyDelete
    Case vbKeyBack
    Case Else
    KeyAscii = 0
    End Select
    End If
    End Sub

    How can I do this in my ASPX page?
    Thanks

  2. #2
    Frenzied Member
    Join Date
    Aug 2000
    Location
    Birmingham, AL
    Posts
    1,276
    The only way I know of is to use an HTML TextField instead of a Web Forms TextBox and use JavaScript.

    The HTML element would look like:
    PHP Code:
    <INPUT onkeypress="return KeyCheck(this, event);" id="txtTest" type="text"
    and the JavaScript:
    PHP Code:
    function KeyCheck(myFielde)
    {
        var 
    key;
        
        if (
    window.event)
            
    key window.event.keyCode;
        else if(
    e)
            
    key e.which;
        else 
            return 
    true;
            
        if (((
    key 47) && (key 58)) || (key == 8))
            return 
    true;
        else 
            return 
    false;


  3. #3

    Thread Starter
    Junior Member
    Join Date
    Mar 2004
    Posts
    19
    thanks this really works

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width