As per our comments, this solution highlights how to sanitize your data inputs if you want to parse them as numeric.
First: It's always best to use numeric inputs or regex's for numeric controls. This helps reduce the issues on the server side and can provide meaningful and responsive information to the user. It's not always possible to do this, so this is how you can handle it server side
(Oh, NB, I'm currently a web developer, so when I say "server side", this could also refer to the code behind your control as apposed the the code controlling the behavior of the control, which I guess I'd call client side)
So: Parsing numeric values. int.Parse will pick out the integers from a string, regardless of letters or anything else, even decimal points. double.Parse cannot ignore the other digits because they could be relevant to the structure of the number. If the structure is not sound, then it throws an error.
You can check if the value is parse-able by using double.TryParse. This will return a boolean value: True=can parse and false=can't parse. You also pass an out parameter so if it can parse, you also get the result.
Take a look:
string alphanum = "123.abc";
string justnum = "123.456";
double result;
if(double.TryParse(alphanum,out result){
Assert.Fail("The parse should return false);
}
Assert.AreEqual(0.0,result); //whatever the 'result' was set to before, it is now zero
if(double.TryParse(justnum ,out result){
Assert.AreEqual(123.456,result);
}
Using this you can check your data before using it. So if the tryparse fails, tell the user that the format it wrong
I hope that helps ^_^
Andy