private void Validating_Number(object sender, CancelEventArgs e) { // Cast the sender object as a control Control oControl = (Control)sender; // try to convert the entry in the textbox // to a number double nNumber; try { if (oControl.Text.Length == 0) oControl.Text = "0"; else nNumber = Convert.ToDouble(oControl.Text); } catch { e.Cancel = true; oControl.Select(); errorProvider1.SetError(oControl, "You must enter a numeric value"); } }