compare2.aspx 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <%@ Page Language="C#" AutoEventWireup="True" %>
  2. <html>
  3. <head>
  4. <script runat="server">
  5. void Button_Click(Object sender, EventArgs e)
  6. {
  7. if (Page.IsValid)
  8. {
  9. lblOutput.Text = "Result: Valid!";
  10. }
  11. else
  12. {
  13. lblOutput.Text = "Result: Not valid!";
  14. }
  15. }
  16. void Operator_Index_Changed(Object sender, EventArgs e)
  17. {
  18. Compare1.Operator = (ValidationCompareOperator) ListOperator.SelectedIndex;
  19. Compare1.Validate();
  20. }
  21. void Type_Index_Changed(Object sender, EventArgs e)
  22. {
  23. Compare1.Type = (ValidationDataType) ListType.SelectedIndex;
  24. Compare1.Validate();
  25. }
  26. </script>
  27. </head>
  28. <body>
  29. <form runat=server>
  30. <h3>CompareValidator Example</h3>
  31. <p>
  32. Enter a value in each textbox. Select a comparison operator<br>
  33. and data type. Click "Validate" to compare values.
  34. <table bgcolor="#eeeeee" cellpadding=10>
  35. <tr valign="top">
  36. <td>
  37. <h5>String 1:</h5>
  38. <asp:TextBox id="TextBox1"
  39. runat="server"/>
  40. </td>
  41. <td>
  42. <h5>Comparison Operator:</h5>
  43. <asp:ListBox id="ListOperator"
  44. OnSelectedIndexChanged="Operator_Index_Changed"
  45. runat="server">
  46. <asp:ListItem Selected Value="Equal">Equal</asp:ListItem>
  47. <asp:ListItem Value="NotEqual">NotEqual</asp:ListItem>
  48. <asp:ListItem Value="GreaterThan">GreaterThan</asp:ListItem>
  49. <asp:ListItem Value="GreaterThanEqual">GreaterThanEqual</asp:ListItem>
  50. <asp:ListItem Value="LessThan">LessThan</asp:ListItem>
  51. <asp:ListItem Value="LessThanEqual">LessThanEqual</asp:ListItem>
  52. <asp:ListItem Value="DataTypeCheck">DataTypeCheck</asp:ListItem>
  53. </asp:ListBox>
  54. </td>
  55. <td>
  56. <h5>String 2:</h5>
  57. <asp:TextBox id="TextBox2"
  58. runat="server"/>
  59. <p>
  60. <asp:Button id="Button1"
  61. Text="Validate"
  62. OnClick="Button_Click"
  63. runat="server"/>
  64. </td>
  65. </tr>
  66. <tr>
  67. <td colspan="3" align="center">
  68. <h5>Data Type:</h5>
  69. <asp:ListBox id="ListType"
  70. OnSelectedIndexChanged="Type_Index_Changed"
  71. runat="server">
  72. <asp:ListItem Selected Value="String" >String</asp:ListItem>
  73. <asp:ListItem Value="Integer" >Integer</asp:ListItem>
  74. <asp:ListItem Value="Double" >Double</asp:ListItem>
  75. <asp:ListItem Value="Date" >Date</asp:ListItem>
  76. <asp:ListItem Value="Currency" >Currency</asp:ListItem>
  77. </asp:ListBox>
  78. </td>
  79. </tr>
  80. </table>
  81. <asp:CompareValidator id="Compare1"
  82. ControlToValidate="TextBox1"
  83. ControlToCompare="TextBox2"
  84. EnableClientScript="False"
  85. Type="String"
  86. runat="server"/>
  87. <br>
  88. <asp:Label id="lblOutput"
  89. Font-Name="verdana"
  90. Font-Size="10pt"
  91. runat="server"/>
  92. </form>
  93. </body>
  94. </html>