CompareValidator DataTypeCheck requires value?

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>
 
R

Ron Weldy

I found the problem and have fixed it. It did not have anything to do with
this, but with some downstream processing. DOH!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,990
Messages
2,570,211
Members
46,796
Latest member
SteveBreed

Latest Threads

Top