Click here to Skip to main content
12,070,351 members (61,373 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: ASP.NET VBScript
Hello All,

I am trying to use a Custom Validator for the validation of the Length of the User Name. I am using VBScript as the scripting language.

But when I try to run the code i am getting an Error.

Below is the script which I am using in m ASP.NET page.
<script language="vbscript" type="text/vbscript">
          Sub Validate (val,arguments)
                If(val.Length=6) Then
                        arguments.IsValid=True
                Else
                        arguments.IsValid=False
                        
                End If
                
          End Sub
                
        
        </script>

Following is the code for the CustomValidtor.
<asp:customvalidator id="CustomValidator1" runat="server" xmlns:asp="#unknown">
            ErrorMessage="User name length should be minimum 6 characters" 
            onservervalidate="CustomValidator1_ServerValidate" 
            ClientValidationFunction="Validate" ControlToValidate="TextBox1">

Kindly assist.
Many Thanks in Advance
Posted 16-Aug-10 9:39am
Comments
aspdotnetdev 16-Aug-10 14:42pm
   
What error are you getting?
Mukund Kallapur 16-Aug-10 14:45pm
   
The execution stops and asks whether to Break, Continue or Ignore pointing to this line "If(val.Length=6) Then"

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

I wish I knew VBScript, but, I don't know it. However, I was able to run the Custom Validation properly using Javascript. Please try to modify the JavaScript code to VBScript, I believe it won't be hard for you Smile | :)

Here is the Code:

(Please note that, I also added a RequiredFieldValidator to validate the empty inputs)

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
    <script language="javascript" type="text/javascript">
          function Validate(sender, args)
          {
             if(args.Value.length == 6)
                args.IsValid = true;
             else
                args.IsValid = false;
          }
        </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
    <asp:CustomValidator id="CustomValidator1" Display="Dynamic" runat="server"
            ErrorMessage="User name length should be minimum 6 characters"
            onservervalidate="CustomValidator1_ServerValidate"
            ClientValidationFunction="Validate" EnableClientScript="true" ControlToValidate="TextBox1"/><asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" Display="Dynamic" ErrorMessage="User name required" ControlToValidate="TextBox1"></asp:RequiredFieldValidator>
        <br />
        <asp:Button ID="Button1" runat="server" Text="Button" />
    </div>
    </form>
</body>
</html>
  Permalink  
Comments
NeenaM 28-Mar-13 14:57pm
   
i have used your above code but i am getting the following error

'ASP.validation_aspx' does not contain a definition for 'CustomValidator1_ServerValidate' and no extension method 'CustomValidator1_ServerValidate' accepting a first argument of type 'ASP.validation_aspx' could be found (are you missing a using directive or an assembly reference)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web01 | 2.8.160208.1 | Last Updated 17 Aug 2010
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100