1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Keypress event handler

Discussion in 'C#' started by markyjj, Apr 25, 2006.

  1. markyjj

    markyjj New Member

    Joined:
    Dec 7, 2005
    Messages:
    19
    Likes Received:
    0
    Trophy Points:
    0
    Am currently trying to create code that clears a text box after a message box is shown when a nonnumeric digit is entered. The code am using doesnt clear the text field as shown below:
    Code:
    if(Char.IsDigit(e.KeyChar) == false)
    			{
    				txtStudID.Focus();
    				txtStudID.Text = "";
                   MessageBox.Show("Please enter a numeric value to continue");
                   
    				
    			}	
    
    Thanks for any help
     
    Last edited by a moderator: Apr 25, 2006
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,285
    Likes Received:
    364
    Trophy Points:
    83
    Does it show the message box.
     
  3. pradeep

    pradeep Team Leader

    Joined:
    Apr 4, 2005
    Messages:
    1,646
    Likes Received:
    86
    Trophy Points:
    0
    Occupation:
    Programmer
    Location:
    Kolkata, India
    Home Page:
    Oh! A simple fix on line 7 would fix that, change line 7 to this

    Code:
    if (document.layers || e.which) { pressedKey = e.which; }
     

Share This Page