Re: CompareValidator DataTypeCheck requires value?

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



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

"Ron Weldy" <ronweldy@xxxxxxx> wrote in message
news:ek6Jb2faFHA.3032@xxxxxxxxxxxxxxxxxxxxxxx
>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>
>


.