C# in asp.net works as C#.

So the problem is with the input.
My guess is that you enter the number in some sort of culture specific value, say using comma as decimal point instead of period, or include some non-value characters.

What exact value do you try to parse? What culture do you parse to and from? I've noticed an en-US in your original code, meaning decimal point is a period. But if you try to parse in, in say culture where period is thousand separator, you'll have issues.