473,395 Members | 1,613 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,395 software developers and data experts.

CompareValidator with DataTypeCheck and dynamically set Type

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'
/>

.... and the following doesn't ...

<asp:CompareValidator
Runat="server"
ControlToValidate="txtValue"
Text="*"
ErrorMessage="The value you provided is not of the correct type."
Operator="DataTypeCheck"
Type='<%# DataBinder.Eval(Container.DataItem,"ASPType") %>'
/>

.... even though I have checked that DataBinder.Eval(Container. DataItem ,
"ASPType") is evaluating to the string value "Double".

The error is pretty cryptic. Here's a part of the trace...

FormatException: Input string was not in a correct format.]
Microsoft.VisualBasic.CompilerServices.DoubleType. Parse(String Value,
NumberFormatInfo NumberFormat)
Microsoft.VisualBasic.CompilerServices.DoubleType. Parse(String Value)
Microsoft.VisualBasic.CompilerServices.IntegerType .FromString(String Value)

[InvalidCastException: Cast from string "Double" to type 'Integer' is not
valid.]
Microsoft.VisualBasic.CompilerServices.IntegerType .FromString(String Value)
Microsoft.VisualBasic.CompilerServices.IntegerType .FromObject(Object Value)

Can anyone help me understand what I'm doing wrong?

Thanks!

Keith Spitz
Wall Street on Demand, Inc.
Nov 18 '05 #1
1 4816
I guess you will have to cast the ASPType to ValidationType
check this

http://msdn.microsoft.com/library/de...stypetopic.asp

The type property is of type ValidationType . Try to cast DataBinder.Eval to
ValidationType.


"Keith Spitz" wrote:
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'
/>

... and the following doesn't ...

<asp:CompareValidator
Runat="server"
ControlToValidate="txtValue"
Text="*"
ErrorMessage="The value you provided is not of the correct type."
Operator="DataTypeCheck"
Type='<%# DataBinder.Eval(Container.DataItem,"ASPType") %>'
/>

... even though I have checked that DataBinder.Eval(Container. DataItem ,
"ASPType") is evaluating to the string value "Double".

The error is pretty cryptic. Here's a part of the trace...

FormatException: Input string was not in a correct format.]
Microsoft.VisualBasic.CompilerServices.DoubleType. Parse(String Value,
NumberFormatInfo NumberFormat)
Microsoft.VisualBasic.CompilerServices.DoubleType. Parse(String Value)
Microsoft.VisualBasic.CompilerServices.IntegerType .FromString(String Value)

[InvalidCastException: Cast from string "Double" to type 'Integer' is not
valid.]
Microsoft.VisualBasic.CompilerServices.IntegerType .FromString(String Value)
Microsoft.VisualBasic.CompilerServices.IntegerType .FromObject(Object Value)

Can anyone help me understand what I'm doing wrong?

Thanks!

Keith Spitz
Wall Street on Demand, Inc.

Nov 18 '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...
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: Ron Weldy | last post by:
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...
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...
1
by: R.A.M. | last post by:
Hi, I am learning .NET 2.0 and I have a problem with asp:CompareValidator. On .aspx page I have: Birth date: <asp:TextBox ID="BirthDate" runat="server" ValidationGroup="BirthDate"/> and it...
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: 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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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...
0
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,...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...

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.