473,725 Members | 2,126 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

CompareValidato r 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 CompareValidato r 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="TxtFl d" Runat="server"
size="2"></asp:TextBox>
<asp:CompareVal idator runat="server"
ControlToValida te="txtCOB"
EnableClientScr ipt="True"
id="valCoB"
CssClass="ErrMs g"
ErrorMessage="P lease enter a number"
Operator="DataT ypeCheck"
Type=Integer>*</asp:CompareVali dator>

</code>
Nov 19 '05 #1
1 1741
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.c om> wrote in message
news:ek******** ******@TK2MSFTN GP10.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 CompareValidato r 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="TxtFl d" Runat="server"
size="2"></asp:TextBox>
<asp:CompareVal idator runat="server"
ControlToValida te="txtCOB"
EnableClientScr ipt="True"
id="valCoB"
CssClass="ErrMs g"
ErrorMessage="P lease enter a number"
Operator="DataT ypeCheck"
Type=Integer>*</asp:CompareVali dator>

</code>

Nov 19 '05 #2

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

Similar topics

0
1000
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! See datagrid code below: <asp:DataGrid id="gridProducts" ....>
2
2232
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 Type property is set to Currency. However, I would like to control check whether the user enters a value or not. Do I have to add an RequiredFieldValidator? Can't CompareValidator handle this? Thanks in advance, Burak
1
4833
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" Type='Double' />
2
3195
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 textbox. I also have a CompareValidator pointed to the textbox with its Type="Date." Despite all documentation to the contrary, I am getting an exception when the page first loads that is thrown by the CompareValidator, complaining that it...
1
1991
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 using DataTypeCheck = Double, the value 199b is refused by the validator. This textbox needs to accept numbers only. What is the difference
1
1456
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: <asp:TextBox ID="BirthDate" runat="server" /> <asp:CompareValidator ID="BirthDateValidation" runat="server" ControlToValidate="BirthDate" Type="Date" Text="Enter date of birth!" /><br />
0
3580
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 format of "dd/MM/yyyy", example: "25/5/2005", it is valid. This works for my development machine, but on the production machine, it complains about this date as invalid. I wonder if anyone else has simalar situation and the solution for this. Any...
3
1186
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 ErrorMessage, theType (integer), yet it still let's the value '2233mm' go through. What else do I need to do?
1
1905
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" ControlToValidate="how to reference a usercontrol's property here??" Operator="DataTypeCheck" Type="Date" ErrorMessage="Please enter a valid start date mm/dd/yyyy)." EnableClientScript="False"> </asp:CompareValidator>
0
8888
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9401
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9257
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8097
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6702
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6011
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4519
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3221
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2635
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.