Since you're parsing the string values to integer values (or double as in the String.Format() block). You need to know that 'a' cannot be converted to an integer. Whereas '0' can be.
What I mean is, that the string contains some characters that are not valid numbers. You need to make sure that the characters are numbers.
Quote:
Input string was not in a correct format.
Above statements tells it all, you need to make sure that the characters are actually numbers and can be converted to double or integers respectively.
On MSDN, a quick Google resulted in this link,
http://msdn.microsoft.com/en-us/library/bb397679.aspx[
^] where it has been made clear that while converting String to other formats like Integer, Double etc, you need to be carefull because String can contain alphanumeric content, whereas double, int, float are restricted to numbers only.
Only way to correct this, is to remove all of the characters from the textboxes that are not numbers, even whitespaces (use
.Trim()
on the string to remove extra spaces at start or end).
Since you're using ASP.NET, in ASP.NET there is a function used to determine whether the string is an int or not, you can use as
if(variableName.IsInt()) {
} else {
}
You can try out many other ways, but remember, always use
if else
block to check for small conditions like this one.