This documentation is archived and is not being maintained.

ControlToCompare Property

.NET Framework 1.1

Sets or returns the ID of the input control to compare. The default value is an empty string ("").

public string ControlToCompare {


Specifies the ID of the control to which a value comparison will be made. You can use the ValueToCompare property as an alternative. If both are specified, the value of the ControlToCompare property takes precedence.


The following example demonstrates how to use the 'ControlToCompare property to verify that the intended password was entered by the user.

<mobile:Form runat=server id="Form1" Alignment=center> 
   <mobile:Label runat="server" id="lblUserPwd" 
      Text="Password (req'd)" />
   <mobile:Textbox  runat="server" id="txtUserPwd"/>
   <mobile:RequiredFieldValidator runat="server" id="rfvUserPwd" 
      ControlToValidate="txtUserPwd" />
   <mobile:RegularExpressionValidator runat="server" id="revUserPwd"
      ControlToValidate="txtUserPwd" />
   <mobile:Label runat="server" id="lblUserPwd2" 
      Text="Re-enter Password (req'd)" />
   <mobile:Textbox  runat="server" id="txtUserPwd2"/>
   <Mobile:CompareValidator runat=server id=valcmprPassword Type=String
      ControlToValidate="txtUserPwd"  Operator=Equal 
      ErrorMessage="Passwords did not match!" 
   <mobile:Command runat="server" id="Command1" text="Submit" />

See Also

Web Forms ControlToCompare Property

Applies to: CompareValidator Class