Solved

CONTROLTOCOMPARE AND CONTROLTOVALIDATE in VB.NET

Posted on 2006-06-18
5
411 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 250 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 250 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 250 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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
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…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

717 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