CompareValidator
CompareValidator Example
Enter a value in each textbox. Select a comparison operator
and data type. Click "Validate" to compare values.
Comparison Operator: |
Data Type: |
||
String 1:String 2: |
|||
@inherits ControlComponent
<p>
Enter a value in each textbox. Select a comparison operator<br />
and data type. Click "Validate" to compare values.
</p>
<table cellpadding="10" style="background-color:#eeeeee;">
<tr valign="top">
<td>
<h5>Comparison Operator:</h5>
</td>
<td>
<asp.ListBox @ref="this.listOperator" AutoPostBack="true"
OnSelectedIndexChanged="this.Operator_Index_Changed">
<asp.ListItem Selected="true" Value="Equal">Equal</asp.ListItem>
<asp.ListItem Value="NotEqual">NotEqual</asp.ListItem>
<asp.ListItem Value="GreaterThan">GreaterThan</asp.ListItem>
<asp.ListItem Value="GreaterThanEqual">GreaterThanEqual</asp.ListItem>
<asp.ListItem Value="LessThan">LessThan</asp.ListItem>
<asp.ListItem Value="LessThanEqual">LessThanEqual</asp.ListItem>
<asp.ListItem Value="DataTypeCheck">DataTypeCheck</asp.ListItem>
</asp.ListBox>
</td>
<td>
<h5>Data Type:</h5>
</td>
<td>
<asp.ListBox @ref="this.listType" AutoPostBack="true"
OnSelectedIndexChanged="this.Type_Index_Changed">
<asp.ListItem Selected="true" Value="String">String</asp.ListItem>
<asp.ListItem Value="Integer">Integer</asp.ListItem>
<asp.ListItem Value="Double">Double</asp.ListItem>
<asp.ListItem Value="Date">Date</asp.ListItem>
<asp.ListItem Value="Currency">Currency</asp.ListItem>
</asp.ListBox>
</td>
</tr>
<tr>
<td colspan="4">
<h5>String 1:</h5>
<asp.TextBox ID="TextBox1" />
<h5>String 2:</h5>
<asp.TextBox ID="TextBox2" />
</td>
</tr>
<tr>
<td colspan="4">
<asp.Button Text="Validate"
OnClick="this.Button_Click" />
</td>
</tr>
</table>
<asp.CompareValidator @ref="this.compare1"
ControlToValidate="TextBox1"
ControlToCompare="TextBox2"
EnableClientScript="false"
Type="ValidationDataType.String" />
<br />
<asp.Label @ref="this.output"
FontNames="verdana"
FontSize="10pt" />
@code {
private Label output;
private ListBox listOperator;
private ListBox listType;
private CompareValidator compare1;
protected void Button_Click(object sender, EventArgs e)
{
if (this.Page.IsValid)
{
output.Text = "Result: Valid!";
}
else
{
output.Text = "Result: Not valid!";
}
}
protected void Operator_Index_Changed(object sender, EventArgs e)
{
compare1.Operator = (ValidationCompareOperator)listOperator.SelectedIndex;
}
protected void Type_Index_Changed(object sender, EventArgs e)
{
compare1.Type = (ValidationDataType)listType.SelectedIndex;
}
}
CompareValidator Metadata
Name | Type | Kind |
---|---|---|
AccessKey | String | Parameter |
Attributes | IReadOnlyDictionary | Parameter |
BackColor | String | Parameter |
BorderColor | String | Parameter |
BorderStyle | BorderStyle | Parameter |
BorderWidth | String | Parameter |
ClientIDMode | ClientIDMode | Parameter |
ControlToCompare | String | Parameter |
ControlToValidate | String | Parameter |
CssClass | String | Parameter |
CultureInvariantValues | Boolean | Parameter |
Display | ValidatorDisplay | Parameter |
EnableClientScript | Boolean | Parameter |
Enabled | Boolean | Parameter |
ErrorMessage | String | Parameter |
FontBold | Boolean | Parameter |
FontItalic | Boolean | Parameter |
FontNames | String | Parameter |
FontOverline | Boolean | Parameter |
FontSize | String | Parameter |
FontStrikeout | Boolean | Parameter |
FontUnderline | Boolean | Parameter |
ForeColor | String | Parameter |
Height | String | Parameter |
ID | String | Parameter |
Operator | ValidationCompareOperator | Parameter |
SetFocusOnError | Boolean | Parameter |
Style | String | Parameter |
TabIndex | Int16 | Parameter |
Text | String | Parameter |
ToolTip | String | Parameter |
Type | ValidationDataType | Parameter |
ValidationGroup | String | Parameter |
ValueToCompare | String | Parameter |
Visible | Boolean | Parameter |
Width | String | Parameter |
OnDataBinding | EventHandler | Event |
OnDisposed | EventHandler | Event |
OnInit | EventHandler | Event |
OnLoad | EventHandler | Event |
OnPreRender | EventHandler | Event |
OnUnload | EventHandler | Event |