Keypress event handler

markyjj's Avatar, Join Date: Dec 2005
Go4Expert Member
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: C#
if(Char.IsDigit(e.KeyChar) == false)
                txtStudID.Text = "";
               MessageBox.Show("Please enter a numeric value to continue");
Thanks for any help

Last edited by shabbir; 25Apr2006 at 20:53.. Reason: Proper formating
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
Does it show the message box.
pradeep's Avatar, Join Date: Apr 2005
Team Leader
Oh! A simple fix on line 7 would fix that, change line 7 to this

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