Last post Apr 22, 2008 03:58 AM by virendra1983
Apr 22, 2008 03:12 AM|arunpulikkan|LINK
I have a text box inm my form. I need to check the value in the textBox is Greater than zero in Server Side. So i tried to do like
Dim txt as Double=TryCast(TxtBox.Text,Double)
if Not(txt isNothing) then
But im Getting error on the
Dim txt as Double=TryCast(TxtBox.Text,Double) error is trycast operand must be reference type,but double is a value type. pla help me
Apr 22, 2008 03:56 AM|johram|LINK
TryCast only works for reference types (i.e. objects). Since double is a value type, you cannot use TryCast for this purpose.
Instead, you should do Double.TryParse(TxtBox.Text, txt) where txt is your Double variable
TryParse returns True if the conversion succeeds, False otherwise. The result of the conversion is stored in the second parameter.
Apr 22, 2008 03:58 AM|virendra1983|LINK
Why are you casting it?
It may have string value also that's why you are using tryCast...
Otherwise you can simply check like this..
if Convert.ToDouble(textbox.text) > 0