我是靠谱客的博主 飞快百褶裙,最近开发中收集的这篇文章主要介绍Comparing Values,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

Comparing Values
It's sometimes useful to be able to validate one control's data by comparing
it to the data in another control or to a specified value. The
CompareValidator control allows you to do both. An example familiar to all
Web users would be the need to compare two entries of a user's password. In
order to confirm that a user has entered the correct password, most sites
require the user to enter the same value twice. Figure 8.4 shows a sample
page comparing two text box controls' values.

Figure 8.4. The CompareValidator control allows you to compare the values
in two controls.


Follow these steps to add the Password Change form to your project:

Select Project, Add Existing Item. Be sure to change the Files of Type
combo box to "All Files (*.*)".

Select all PwdChange.* files from the Jumpstart/ValidationControls folder.
There should be three files: PwdChange.aspx, PwdChange.aspx.resx, and
PwdChange.aspx.vb.

Bring up the PwdChange.aspx file in design mode.

Click immediately to the right of the Confirm Password text box to place
the insertion point after the control.

In the Toolbox window, double-click the CompareValidator control to place a
new instance of the control to the right of the Confirm Password text box.

Set the properties of the new control as shown in Table 8.7.

Table 8.7. Set These Properties in the CompareValidator Control Property
Value
ControlToCompare txtPassword
ControlToValidate txtConfirm
ErrorMessage 'Password' and 'Confirm Password' must match


Run the application, bring up the Password Change page, and attempt to
change the password. Check out what happens when you enter two different
passwords on the page梱ou should see the error message displayed in the
CompareValidator control.

OTHER USES FOR THE COMPAREVALIDATOR CONTROL
The CompareValidator control does more than just compare the values of two
controls. You can also compare a control to a specific value. In addition,
the Operator property of the control allows you to check for other
comparisons besides equality. The Operator property can be any of these
values: Equal (the default value), NotEqual, GreaterThan, GreaterThanEqual,
LessThan, LessThanEqual, or DataTypeCheck. This last option, DataTypeCheck,
allows you to simply check that the value entered into the control matches
a specific data type. If you select DataTypeCheck for the Operator property
and set the Type property to Date, for example, and leave ControlToCompare
and ValueToCompare empty, you can allow the user to enter any date, but
only a date.
 

最后

以上就是飞快百褶裙为你收集整理的Comparing Values的全部内容,希望文章能够帮你解决Comparing Values所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(33)

评论列表共有 0 条评论

立即
投稿
返回
顶部