Jul 30, 2010

ASP.NET custom validation Control

<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>
    

<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>


Output Result:

Enter a username:

A username must be between 8 and 16 characters!

No comments:

Post a Comment