Hi,
I have a WebCurrencyEdit controll on an ASPX form.The DataMode property is set to Decimal.The Nullable property is set to true.My problem is that if the input field is left empty, the WebCurrencyEdit control sends a zero value instead of NULL back to the server.
I can use a Text DataMode to work around this problem but the problem in this case is that the currency name is not removed automatically.
Is there some nice solution to this problem?
This worked for me... Thank you :)
Hi,Originally WebCurrencyEdit was written for CLR1 which did not have Nullable data type. Since primitive numeric data types like int, long, decimal do not support null and therefore 0 is used if value is missing.
The DataType affects object returned by the "get" of Value property and for decimal data type it will never be null. The "set" for Value will take any object.
If your application needs decimal and value null, then I suggest to use ValueDouble property as a flag for null. It does not matter to which type DateType property is set, internally WebCurrency/NumericEditor uses double anyway. I suggest to keep default "Double".
double value = this.WebCurrencyEdit1.ValueDouble;decimal? decimalVal = null;if(!double.IsNaN(value)) decimalVal = (decimal)value;