1
<%
@ Page Language
=
"
C#
"
%>
2
3 < script runat = " server " >
4
5 protected void Button1_Click(Object sender, EventArgs e) {
6 if (Page.IsValid)
7 Label1.Text = " Passwords match " ;
8 }
9
10 </ script >
11
12 < html xmlns = " http://www.w3.org/1999/xhtml " >
13 < head id = " Head1 " runat = " server " >
14 < title > CompareFieldValidator </ title >
15 </ head >
16 < body >
17 < form id = " Form1 " runat = " server " >
18 < p >
19 Password < br >
20 < asp:TextBox ID = " TextBox1 " Runat = " server " TextMode = " Password " ></ asp:TextBox >
21 & nbsp;
22 < asp:CompareValidator ID = " CompareValidator1 " Runat = " server " ErrorMessage = " Passwords do not match! "
23 ControlToValidate = " TextBox2 "
24 ControlToCompare = " TextBox1 " ></ asp:CompareValidator >
25 </ p >
26 < p >
27 Confirm Password < br >
28 < asp:TextBox ID = " TextBox2 " Runat = " server " TextMode = " Password " ></ asp:TextBox >
29 </ p >
30 < p >
31 < asp:Button ID = " Button1 " OnClick = " Button1_Click " Runat = " server " Text = " Login " ></ asp:Button >
32 </ p >
33 < p >
34 < asp:Label ID = " Label1 " Runat = " server " ></ asp:Label >
35 </ p >
36 </ form >
37 </ body >
38 </ html >
2
3 < script runat = " server " >
4
5 protected void Button1_Click(Object sender, EventArgs e) {
6 if (Page.IsValid)
7 Label1.Text = " Passwords match " ;
8 }
9
10 </ script >
11
12 < html xmlns = " http://www.w3.org/1999/xhtml " >
13 < head id = " Head1 " runat = " server " >
14 < title > CompareFieldValidator </ title >
15 </ head >
16 < body >
17 < form id = " Form1 " runat = " server " >
18 < p >
19 Password < br >
20 < asp:TextBox ID = " TextBox1 " Runat = " server " TextMode = " Password " ></ asp:TextBox >
21 & nbsp;
22 < asp:CompareValidator ID = " CompareValidator1 " Runat = " server " ErrorMessage = " Passwords do not match! "
23 ControlToValidate = " TextBox2 "
24 ControlToCompare = " TextBox1 " ></ asp:CompareValidator >
25 </ p >
26 < p >
27 Confirm Password < br >
28 < asp:TextBox ID = " TextBox2 " Runat = " server " TextMode = " Password " ></ asp:TextBox >
29 </ p >
30 < p >
31 < asp:Button ID = " Button1 " OnClick = " Button1_Click " Runat = " server " Text = " Login " ></ asp:Button >
32 </ p >
33 < p >
34 < asp:Label ID = " Label1 " Runat = " server " ></ asp:Label >
35 </ p >
36 </ form >
37 </ body >
38 </ html >
类型的判断:
1
Age:
2 < asp:TextBox ID = " TextBox1 " Runat = " server " MaxLength = " 3 " ></ asp:TextBox >
3 & nbsp;
4 < asp:CompareValidator ID = " CompareValidator1 " Runat = " server " Text = " You must enter a number " ControlToValidate = " TextBox1 " Type = " Integer "
5 Operator = " DataTypeCheck " ></ asp:CompareValidator >
2 < asp:TextBox ID = " TextBox1 " Runat = " server " MaxLength = " 3 " ></ asp:TextBox >
3 & nbsp;
4 < asp:CompareValidator ID = " CompareValidator1 " Runat = " server " Text = " You must enter a number " ControlToValidate = " TextBox1 " Type = " Integer "
5 Operator = " DataTypeCheck " ></ asp:CompareValidator >
1
Age:
2 < asp:TextBox ID = " TextBox1 " Runat = " server " ></ asp:TextBox >
3 & nbsp;
4 < asp:CompareValidator ID = " CompareValidator1 " Runat = " server " Operator = " GreaterThan " ValueToCompare = " 18 " ControlToValidate = " TextBox1 "
5 Text = " You must be older than 18 to join " Type = " Integer " >
6 </ asp:CompareValidator >
2 < asp:TextBox ID = " TextBox1 " Runat = " server " ></ asp:TextBox >
3 & nbsp;
4 < asp:CompareValidator ID = " CompareValidator1 " Runat = " server " Operator = " GreaterThan " ValueToCompare = " 18 " ControlToValidate = " TextBox1 "
5 Text = " You must be older than 18 to join " Type = " Integer " >
6 </ asp:CompareValidator >
1
Age:
2 < asp:TextBox ID = " TextBox1 " Runat = " server " ></ asp:TextBox >
3 & nbsp;
4 < asp:RangeValidator ID = " RangeValidator1 " Runat = " server " ControlToValidate = " TextBox1 " Type = " Integer "
5 Text = " You must be between 30 and 40 " MaximumValue = " 40 " MinimumValue = " 30 " ></ asp:RangeValidator >
2 < asp:TextBox ID = " TextBox1 " Runat = " server " ></ asp:TextBox >
3 & nbsp;
4 < asp:RangeValidator ID = " RangeValidator1 " Runat = " server " ControlToValidate = " TextBox1 " Type = " Integer "
5 Text = " You must be between 30 and 40 " MaximumValue = " 40 " MinimumValue = " 30 " ></ asp:RangeValidator >