Use both client side and server side script to validate (VB.net) : CustomValidator « Validation « ASP.NET Tutorial






<%@ Page Language="VB" %>

<script runat="server">
   sub Submit(Sender as Object, e as EventArgs)
      if Page.IsValid then
         lblMessage.Text = "It's all good!"
      end if
   end sub
   
   sub ValidateThis(Sender as Object, args as _
   ServerValidateEventArgs) 
   if len(args.Value) < 8 then
      args.IsValid = false
   else
      args.IsValid = true
   end if
end sub

</script>

<script language="JavaScript">
   function validateLength( oSrc, txtValue ){
      var retValue = true;
      if(txtValue.length < 8){
         retValue = false;
      }
      return retValue
   }
</script>

<html><body>
   <form runat="server">
      <asp:Label id="lblMessage" runat="server" />
      <table>
      <tr>
         <td valign="top">Username:</td>
       <td valign="top">
            <asp:Textbox id="tbUserName" runat="server" 
               /><br>
            <asp:CustomValidator runat="server"
               OnServerValidate="ValidateThis" 
               OnClientValiate="validateLength" 
               Display="Dynamic"
               ControlToValidate="tbUserName"
               ErrorMessage="The username must be 8 characters or longer"/>
       </td>
    </tr>
    <tr>
         <td align="right" colspan="2">
          <ASP:Button id="tbSubmit" runat="server" 
             OnClick="Submit" 
             text="Submit" />
       </td>
    </tr>
      </table>   
   </form>
</body></html>








8.3.CustomValidator
8.3.1.You can associate a custom validation function with the CustomValidator control.
8.3.2.Validate a blank field
8.3.3.Performing validation against no particular field.
8.3.4.Use both client side and server side script to validate (VB.net)
8.3.5.Create user control based on CustomValidator
8.3.6.Using the CustomValidator control to perform client-side validations
8.3.7.Using the CustomValidator control to perform server-side validations (C#)
8.3.8.Using the CustomValidator control to perform server-side validations (VB)
8.3.9.Custom validator with Javascript
8.3.10.CustomValidator for login page
8.3.11.CustomValidator for login page (VB)