?
Solved

CONTROLTOCOMPARE AND CONTROLTOVALIDATE in VB.NET

Posted on 2006-06-18
5
Medium Priority
?
414 Views
Last Modified: 2008-03-10
in the compare validatore in VB.NET, there is CONTROLTOCOMPARE  and CONTROLTOVALIDATE.

can someone explain to e how we use this?

thanks
 
0
Comment
Question by:jskfan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 19

Assisted Solution

by:arif_eqbal
arif_eqbal earned 1000 total points
ID: 16931798
The Compare Validator is used when you want the value in a control to be in some way related to the value in another control, say you have two text boxes Txt1 and Tx2 you want that the value in Txt2 must be smaller than thatof Txt1 in that case you would use the Compare validator and here Control to Validate would be Txt2 and Control to Compare would be Txt1
For more info look at the examples at the site
http://www.w3schools.com/aspnet/control_comparevalidator.asp
0
 

Author Comment

by:jskfan
ID: 16944368
I will test it and  get back with you later.
0
 

Author Comment

by:jskfan
ID: 16947537
In The Compare Validator there is:

ControlToCompare
ControlToValidate
Operator
ValueToCompare

there is textbox1 and textbox2

if I want textbox2 to have a number of 9 or greater than 9
and the number entered in textbox2 to be greater than the number entered in textbox1.

how should I do that?

0
 
LVL 19

Accepted Solution

by:
arif_eqbal earned 1000 total points
ID: 16948531
There are two validations that you require now
1. TextBox1 should have an Integer value Greater than or equal to 9
2. TextBox2 should have an Integer value greater than TextBox1 value

So we need 2 Validation controls
1. RangeValidator
    Put a Range Validator on your fomr and set the following properties
    ControlToValidate = TextBox1
    MinimumValue = 9
    MaximumValue = 65000 '(any max value that you want)
    Type = Integer

2. CompareValidator
    Put a CompareValidator and set the following properties
    ControlToValidate = TextBox2
    ControlToCompare = TextBox1
    Operator = "Greater Than"
    Type = Integer

Now test your App....
The properties are self explanatory though I'd just briefly describe what's being done
ControlToValidate is always the control that will be validated
ControlToCompare is the control whose value would be used for comparison and the comaprison could be "Equal To", "Greater Than" etc. and this is the Operator, lastly the Type tells us what data type we are trying to compare.
Property ValueToCompare is not required here, it is used to specify a static value to compare to, i.e. in case you wanted that instead of comparing the value with the TextBox1 value use a constant value you'd use that.
0
 
LVL 19

Assisted Solution

by:arif_eqbal
arif_eqbal earned 1000 total points
ID: 16948680
On the side Note, there are a few things, about validation controls, to remember
1. "No value" is a valid entry except in the case of RequiredFieldValidator
    >>   To test it, do not enter anything in the TextBox1 and click the PostBack button, it will not raise validation Error

2. If the value of the target control in the ControlToValidate property cannot be converted to the appropriate data type, validation Error is thrown
    >>  To test put a string or a char in textbox1 and check it will give validation error

3. If the value of the target control in the ControlToCompare property cannot be converted to the appropriate data type, No Error is thrown
    >> It means that if TextBox1 contained a string or a char and we said validate that TextBox2 has an Integer value greater than that in TextBox1 the result would always be "No Error" because the string in textbox1 can not be converted to Integer so no error is thrown
    To test this put a new TextBox say TextBox3, now change the CompareValidator's ControlToCompare property from textbox1 to TextBox3, Now if you put an integer in TextBox3 and test the TextBox2 value to be greater than this value it will validate properly, but if you enter a string in TextBox3 and validate it will never give Validation Error
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Suggested Courses
Course of the Month10 days, 14 hours left to enroll

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question