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,337
    Likes Received:
    377
    Trophy Points:
    83
    Does it show the message box.
     
  3. pradeep

    pradeep Team Leader

    Joined:
    Apr 4, 2005
    Messages:
    1,645
    Likes Received:
    87
    Trophy Points:
    0
    Occupation:
    Programmer
    Location:
    Kolkata, India
    Home Page:
    http://blog.pradeep.net.in
    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

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice