473,385 Members | 1,764 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

CompareValidator DataTypeCheck requires value?

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>
Nov 19 '05 #1
1 1729
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" <ro******@msn.com> wrote in message
news:ek**************@TK2MSFTNGP10.phx.gbl...
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>

Nov 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Sjaakie Helderhorst | last post by:
Hi, Somehow pushing an image-button doesn't trigger the CompareValidator, resulting in errors when entering string characters. Could someone please tell me what I did wrong? Thanks in advance!...
2
by: buran | last post by:
Dear ASP.NET Programmers, I am using a CompareValidator control to check the values entered into a texbox. The textbox is for currencies, so the property Operator is set to DataTypeCheck and the...
1
by: Keith Spitz | last post by:
The following works... <asp:CompareValidator Runat="server" ControlToValidate="txtValue" Text="*" ErrorMessage="The value you provided is not of the correct type." Operator="DataTypeCheck"...
2
by: Eric Maia | last post by:
I have a textbox (StartDateTextBox) in a UserControl on my page, that is supposed to have a date entered into it. I have a RequiredFieldValidator that has its ControlToValidate property set to the...
1
by: Chris Leffer | last post by:
Hi. I set a CompareValidator using DataTypeCheck = Integer to validate a textbox. When I type 199b on the textbox, the validator control accepts the value. If I set the same validator control...
1
by: R.A.M. | last post by:
Hello, (Sorry for my English...) Could you help me please? I have a problem with CompareValidator control which makes the load of my page infinitive. Here's the code: Date of birth:...
0
by: weilinyu | last post by:
Hi Everyone, I have a web portal. On one of my web forms, I have a Comparevalidator for my textbox "FuellingDate". I configured it to do a DataTypeCheck for Date. When user puts in a date in a...
3
by: =?Utf-8?B?Y2FzaGRlc2ttYWM=?= | last post by:
Hi, I have added a CompareValidator to my .NET 2.0 web page and told it to validate against Integers. I set the ControlToValidate, the Text, Display (tried both Static and Dynamic),the...
1
by: =?Utf-8?B?RGF2ZQ==?= | last post by:
Is there a way to validate a usercontrol's property from the page hosting the control using a comparevalidator control? such as? <asp:CompareValidator id="cvStartDate" runat="server"...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.