System.Web.UI.WebControls Namespace CompareValidator Class
Sets or retrieves a constant value to compare with.
Inline |
<asp:comparevalidator valuetocompare = strValue ... > |
Script |
CompareValidator.ValueToCompare = strValue |
strValue |
String specifying the constant value to compare with the value entered by the user into the input control being validated. |
The property is read/write with no default value.
Use the ValueToCompare property to specify a constant value to compare with the value entered by the user into the input control being validated.
You can either compare the value of an input control to another input control, or to a constant value. However, you can not set both the ControlToCompare and ValueToCompare properties at the same time. If both properties are set, ControlToCompare takes precedence.
If the constant value specified by this property fails to convert to the data type specified by the Type property, an exception is thrown.
The following example shows how to declaratively set the ValueToCompare property of a CompareValidator control at design time.
<asp:comparevalidator id = "compValidator"
controltovalidate = "myTextBox"
valuetocompare = "0" type = "Integer"
enableclientscript = "False"
runat = "server" />
The example below shows how to programmatically set that same ValueToCompare property above at run time.
Random rand_number = new Random ( );
compValidator.ValueToCompare = rand_number.Next ( 1, 10 ).ToString ( );
Show me
CompareValidator Members Validating Against a Specific Value