简单教程
提交运行
代码编辑器:
<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> <meta charset="utf-8" /> <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>
运行结果: