Comparing Values

博客介绍了CompareValidator控件的用途,它可用于比较两个控件的数据或控件与指定值。以用户密码确认场景为例,展示了添加密码更改表单及设置控件属性的步骤。此外,该控件还能进行多种比较操作,其Operator属性有多种取值。
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.
 
git config usage: git config [<options>] Config file location --[no-]global use global config file --[no-]system use system config file --[no-]local use repository config file --[no-]worktree use per-worktree config file -f, --[no-]file <file> use given config file --[no-]blob <blob-id> read config from given blob object Action --[no-]get get value: name [value-pattern] --[no-]get-all get all values: key [value-pattern] --[no-]get-regexp get values for regexp: name-regex [value-pattern] --[no-]get-urlmatch get value specific for the URL: section[.var] URL --[no-]replace-all replace all matching variables: name value [value-pattern] --[no-]add add a new variable: name value --[no-]unset remove a variable: name [value-pattern] --[no-]unset-all remove all matches: name [value-pattern] --[no-]rename-section rename section: old-name new-name --[no-]remove-section remove a section: name -l, --[no-]list list all --[no-]fixed-value use string equality when comparing values to 'value-pattern' -e, --[no-]edit open an editor --[no-]get-color find the color configured: slot [default] --[no-]get-colorbool find the color setting: slot [stdout-is-tty] Type -t, --[no-]type <type> value is given this type --bool value is "true" or "false" --int value is decimal number --bool-or-int value is --bool or --int --bool-or-str value is --bool or string --path value is a path (file or directory name) --expiry-date value is an expiry date Other -z, --[no-]null terminate values with NUL byte --[no-]name-only show variable names only --[no-]includes respect include directives on lookup --[no-]show-origin show origin of config (file, standard input, blob, command line) --[no-]show-scope show scope of config (worktree, local, global, system, command) --[no-]default <value> with --get, use default value when missing entry --[no-]comment <value> human-readable comment string (# will be prepended as needed) 这样意味着设置好用户名和电子邮箱了吗
最新发布
10-08
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值