0

I have one custom validator, one textbox & one button..I m checking the length of data entered in textbox.

VB CODE

<asp:CustomValidator ID="CustomValidator1" runat="server"  OnServerValidate="ValidateThis"
 ErrorMessage="The username must be 8" ControlToValidate="TextBox4"></asp:CustomValidator></td>
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

  <script runat="server">
      
      Sub ValidateThis(ByVal Sender As Object, ByVal args As _
       ServerValidateEventArgs)
          If Len(args.Value) < 8 Then
              args.IsValid = False
          Else
              args.IsValid = True
          End If
      End Sub
    </script>


<html xmlns="http://www.w3.org/1999/xhtml" >

<head runat="server">

When i click on button,page is postbacked,if the length is less than 8 error msg comes,else nothing.

Mine C# Equivalent code-

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
<script runat ="server" >
void ValidateThis(object Sender,ServerValidateEventArgs args)
{
    if(len(args.Value)< 0)
    {
        args.IsValid = false; 
    }
                else
          args.IsValid = true ; 
        }
  </script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">

ERROR - The name 'len' does not exist in the current context

2
Contributors
2
Replies
4
Views
8 Years
Discussion Span
Last Post by mansi sharma
0
<script runat="server">
void CustomValidator1_ServerValidate(object source, ServerValidateEventArgs args)
    {
        if (args.Value.Length < 8)
        {
            args.IsValid = false;
        }
        else
        {
            args.IsValid = true;
        }

    }
      
    </script>

replace your Script with the above code
try this ......
Chithra

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.