代碼:
<script runat="server">sub check_operator(sender As Object, e As EventArgs)
compval.Operator=CType(list.SelectedIndex,ValidationCompareOperator)
compval.Validate()
end sub
</script>
<!DOCTYPE html>
<html>
<body>
<form runat="server">
<table border="0" bgcolor="#b0c4de">
<tr valign="top">
<td colspan="4"><h4>Compare two values</h4></td>
</tr>
<tr valign="top">
<td><asp:TextBox id="txt1" runat="server" /></td>
<td>
<asp:ListBox id="list" rows="2" OnSelectedIndexChanged="check_operator" runat="server">
<asp:ListItem value="Equal" selected>=</asp:ListItem>
<asp:ListItem value="NotEqual"><></asp:ListItem>
</asp:ListBox>
</td>
<td><asp:TextBox id="txt2" runat="server" /></td>
<td><asp:Button Text="Validate" runat="server" /></td>
</tr>
</table>
<br>
<asp:CompareValidator
id="compval"
Display="dynamic"
ControlToValidate="txt1"
ControlToCompare="txt2"
ForeColor="red"
BackColor="yellow"
Type="String"
EnableClientScript="false"
Text="Validation Failed!"
runat="server" />
</form>
</body>
</html>
結(jié)果:
- ASP.NET 事件句柄
- ASP.NET 數(shù)據(jù)綁定
- ASP.NET Label 控件
- WebSecurity RequireAuthenticatedUser 方法
- ASP.NET HTML 控件 Calendar 3
- ASP.NET HTML 控件 Hyperlink
- ASP.NET HTML 控件 Repeater
- ASP.NET HTML 控件 SortedList RadioButtonList 1
- ASP.NET HTML 控件 SortedList RadiobuttonList 2
- VB 實例 For 循環(huán)
- VB 實例 Else If 條件
- VB 實例 Select 條件
- C# 實例 使用 Chart 幫助器 根據(jù) XML 文件顯示餅圖
- ASP.NET BorderWidth 屬性
- ASP.NET CalendarDay IsToday 屬性
- ASP.NET RadioButtonList RepeatColumns 屬性
- ASP.NET Style BorderStyle 屬性
- ASP.NET Table HorizontalAlign 屬性
- 檢查用戶是否仍然與服務(wù)器相連
- 返回指定文件的屬性