ASP.NET HTML 控件 CustomValidator

asp.net html 控件 customvalidator

<script  runat="server">
sub user(source as object,args as servervalidateeventargs)
   if len(args.value)<8 or len(args.value)>16 then
    args.isvalid=false
   else
    args.isvalid=true
   end if
end sub
</script>
     

<!doctype html>
<html>
<body>

<form runat="server">
<asp:label runat="server" text="enter a username: " />
<asp:textbox id="txt1" runat="server" />
<asp:button text="submit" runat="server"/>
<br>
<asp:label id="mess" runat="server"/>
<br>
<asp:customvalidator
controltovalidate="txt1"
onservervalidate="user"
text="a username must be between 8 and 16 characters!"
runat="server"/>
</form>

</body>
</html>
相关文章