Validation question
I have the following method, IN MY WINDOWS FORM, that I am trying to call in another part of my code:
private bool IsNumeric( string TextValue )
{
bool IsNumeric = false;
try
{
Convert.ToInt32( TextValue );
IsNumeric = true;
}
catch ( Exception e ) { }
return IsNumeric;
}
Here is where I am trying to make a call to the method above to check and see if what the user is entering in the textbox is a NUMERIC value. If an ALPHA character is contained in the textbox then launch the message box that I have listed below:
private void Load_Datagrid()
{
Cursor.Current = Cursors.WaitCursor;
//If the CLIENTID field is left blank or a NON-NUMERIC value is entered then pop-up this message box.
if (txtClientID.Text.ToString().Length < 1 || IsNumeric(txtClientID.Text.ToString()))
{
System.Windows.Forms.MessageBox.Show(this,"A NUMERIC Client ID must be entered."); //\n\n\t", System.Windows.Forms.MessageBoxButtons.OK,System.W indows.Forms.MessageBoxIcon.Warning);
return;
}
Any HELP or DIRECTION would be appreciated. I am just getting an exception error and NOT my message box.
Thanks.
|