Results 1 to 3 of 3

Thread: CustomValidator

  1. #1
    Join Date
    Dec 1969

    Default CustomValidator

    I am trying to use the customvalidator object and I am have having no luck. The script I wrote works fine - no errors; however, when I use the CV it throws an error - (Line: 316 object expected).<BR><BR>I did some research and noticed that you need to pass (source, arguments). I return arguments.IsValid = true ... etc. Here is a sample of the code in JS/<BR><BR>JS:<BR> function validateCC(source, arguments) {<BR> if (arguments.value%2 == 0) {<BR> arguments.IsValid = true;<BR> } else {<BR> arguments.IsValid = false;<BR> }<BR> }<BR><BR><BR>&#060;asp:CustomValidator<BR> ID="CVccNumber" <BR> Runat="server"<BR> ControlToValidate="ccNumber"<BR> ClientValidationFunction="validateCC"<BR> ErrorMessage="*"<BR>/&#062;<BR><BR>If you see something or know of any bugs - please let me know. <BR><BR>Thanks,<BR>Todd

  2. #2
    Join Date
    Dec 1969

    Default Couple of changes here...

    Javascript, being case-sensitive, needs &#039;Value&#039; to be accessed with a capital &#039;V&#039;.<BR><BR><BR><BR>function validateCC(source, arguments)<BR>{ <BR> // always helps to do a bit of debugging :)<BR> alert(typeof(source)) ;<BR> alert(typeof(arguments)) ;<BR> // note that the Value property of the arguments<BR> // class is spelt with a capital &#039;V&#039;<BR> alert(arguments.Value) ;<BR> <BR> if (arguments.Value%2 == 0)<BR> { <BR> arguments.IsValid = true ; <BR> } else { <BR> arguments.IsValid = false ; <BR> } <BR>}

  3. #3
    Join Date
    Dec 1969

    Default RE: CustomValidator

    I too am experiencing problems with the CustomValidator using JScript. My code:<BR><BR>function ValidateLength(source, args)<BR>{ <BR> if (len(args.value) &#060; 3)<BR> {<BR> args.IsValid = false;<BR> }<BR> else<BR> {<BR> args.IsValid = true;<BR> }<BR>}<BR><BR>Here&#039;s where it gets weird. It seems that the Validator is trying to fire off the script on a OnBlur() event (when the focus leaves the textbox). This chucks a "Object expected" error. Whats screwy is that when the form is posted the Validator fires off again without any errors and performing all the validations correctly. Frankly this pisses me off. Examples ripped from Microsofts site are error the same way. <BR><BR>-rpeters

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts