ASP.NET HTML 控件 CompareValidator 2

asp.net html 控件 comparevalidator 2

<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>
相关文章