I'm using ASP.NET CompareValidator controls to do data type checks. Should I trust these controls enough to directly parse their values or should I use TryParse?
Example:
<asp:TextBox ID="uxVolume" runat="server" />
<asp:CompareValidator ID="uxVolumeDataTypeValidator" runat="server"
ControlToValidate="uxVolume" ErrorMessage="Volume must be a number."
Type="Double" Operator="DataTypeCheck" Text="*" Display="Dynamic" />
in the code behind page should I Parse:
var volume = double.Parse(uxVolume.Text);
// do something
or TryParse:
double volume;
if (double.TryParse(uxVolume.Text, out volume))
{
// do something
}