R
Ron Weldy
I want to have a optional field on a form that can be blank but if the user
enters something, it must be a number. I'm using a CompareValidator with the
datatype check but if I submit the form with no value in the field it throws
an error. If I put a number in the form submits fine, and a non-numeric will
trigger the validation. But blank causes the nasty error page to come up
with the error " Input string was not in a correct format."
Can this be done?
Here is my code:
<code>
<asp:TextBox id=txtCOB maxLength="3" CssClass="TxtFld" Runat="server"
size="2"></asp:TextBox>
<asp:CompareValidator runat="server"
ControlToValidate="txtCOB"
EnableClientScript="True"
id="valCoB"
CssClass="ErrMsg"
ErrorMessage="Please enter a number"
Operator="DataTypeCheck"
Type=Integer>*</asp:CompareValidator>
</code>
enters something, it must be a number. I'm using a CompareValidator with the
datatype check but if I submit the form with no value in the field it throws
an error. If I put a number in the form submits fine, and a non-numeric will
trigger the validation. But blank causes the nasty error page to come up
with the error " Input string was not in a correct format."
Can this be done?
Here is my code:
<code>
<asp:TextBox id=txtCOB maxLength="3" CssClass="TxtFld" Runat="server"
size="2"></asp:TextBox>
<asp:CompareValidator runat="server"
ControlToValidate="txtCOB"
EnableClientScript="True"
id="valCoB"
CssClass="ErrMsg"
ErrorMessage="Please enter a number"
Operator="DataTypeCheck"
Type=Integer>*</asp:CompareValidator>
</code>