Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / February 2008

Tip: Looking for answers? Try searching our database.

Client-Side Validation with Validators and JavaScript

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Nathan Sokalski - 11 Feb 2008 05:55 GMT
I am trying to learn a little more about how to add client-side validation
to custom validators that I write (by inheriting from the BaseValidator
class). I know that the name of the JavaScript function is assigned to an
attribute named 'evaluationfunction' and that the function returns true or
false. However, some of the things I don't know or are unclear about are:

1. What parameters does the function assigned to evaluationfunction receive?
If they are objects, what properties do they have?

2. On several of the websites I was looking at for help, they said the
function assigned to evaluationfunction had 2 parameters, but were unclear
on what they were.

3. One of the validators (or actually types of validators) I am working on
writing is validators that use client callbacks (also known as AJAX). I know
how to implement the ICallbackEventHandler, but since the callback must be
initiated by JavaScript, I am assuming the callback statement would be in
the function used for evaluationfunction. However, this would require
calling a function to apply the validation after returning from the
callback. From what I could get from the sites I could find, this would
involve calling the ValidatorUpdateDisplay function that exists in the
WebUIValidation.js file after returning. However, I was having a little
trouble figuring out what to pass it and where to get that value.

If anybody could help me here, it would be greatly appreciated. Thanks.
Signature

Nathan Sokalski
njsokalski@hotmail.com
http://www.nathansokalski.com/

Manish - 11 Feb 2008 09:01 GMT
Hi Nathan,

Please refer to this link below for client side validation using the
CustomValidator control.

http://quickstarts.asp.net/QuickStartv20/aspnet/doc/validation/default.aspx

The CustomValidator server control calls a user-defined function to perform
validations that the standard validators can't handle. The custom function
can execute on the server or in client-side script, such as JScript or
VBScript. For client-side custom validation, the name of the custom function
must be identified in the ClientValidationFunction property. The custom
function must have the form function myvalidator(source, arguments). Note
that source is the client-side CustomValidator object, and arguments is an
object with two properties, Value and IsValid. The Value property is the
value to be validated and the IsValid property is a Boolean used to set the
return result of the validation.

Regards,
Manish

www.ComponentOne.com

> I am trying to learn a little more about how to add client-side validation
> to custom validators that I write (by inheriting from the BaseValidator
[quoted text clipped - 21 lines]
>
> If anybody could help me here, it would be greatly appreciated. Thanks.
Nathan Sokalski - 11 Feb 2008 16:17 GMT
First of all, I am not looking for information about the CustomValidator
control, I am inheriting the BaseValidator class, which does not have a
ClientValidationFunction property. I also need to know about the
ValidatorUpdateDisplay JavaScript function.
Signature

Nathan Sokalski
njsokalski@hotmail.com
http://www.nathansokalski.com/

> Hi Nathan,
>
[quoted text clipped - 54 lines]
>>
>> If anybody could help me here, it would be greatly appreciated. Thanks.
bruce barker - 11 Feb 2008 17:24 GMT
the basevalidator has no builtin support for calling clientfunctions, you
will need to write the hookup code yourself. client validation is pretty
simple. validators are rendered as a span. then javascript code is rendered
to create a javascript variable that references the span. then expando
properties are added to this variable. your valiadation code would add
additional properties via RegisterExpandoAttribute.

there are 7 expando properties the base validator renders:

 enabled - bool used to enable/disable validation
 controltovalidate - the ClientId of the control to validate
 focusOnError - bool used to indicate set focus action
 errormessage - message to display if not valid
 display - display type
 isvalid - results of validation (set by the caller)
 validationGroup - the validation group

if you want a client function called, your code needs to add the expando
attribute:

 evaluationfunction - name of the client function to cal

the evaluationfunction is called with one arg, the validator instance. your
client code can then look at any expando attributes to decided what action to
take. this fuction should return true/false for valid/not valid

the CustomValidator will render the evaluationfunction based on the
ClientValidationFunction server property. it will call the client function
with two args

 clientFunction (val, args)

where val is the validaor instance, and args is an object with two properties

 args.Value - the value of the control to validate
 args.IsValid - always initialized to true
 
after the custom validator calls your client fucntion it returns
args.IsValid to its caller (the standard validation code), and does not  use
your functions return value.

one advantage of the custom validator (besides hooking the client function)
is it has generic code to determine the value of the control to validate. if
you use the base, you will need to write this code.

pretty simple actually.

-- bruce (sqlwork.com)

> I am trying to learn a little more about how to add client-side validation
> to custom validators that I write (by inheriting from the BaseValidator
[quoted text clipped - 21 lines]
>
> If anybody could help me here, it would be greatly appreciated. Thanks.
Nathan Sokalski - 11 Feb 2008 19:58 GMT
That definitely helps clear up the difference between client validation for
CustomValidators and other validators, as well as what properties their
parameters have, it was a big help. However, in order to create the
validators I am attempting to make that use client callbacks, I believe I
need a little more information about ValidatorUpdateDisplay, or any other
steps I need to take or methods I need to call to update the validation
status without returning a value from the evaluationfunction. Thanks.
Signature

Nathan Sokalski
njsokalski@hotmail.com
http://www.nathansokalski.com/

> the basevalidator has no builtin support for calling clientfunctions, you
> will need to write the hookup code yourself. client validation is pretty
[quoted text clipped - 84 lines]
>>
>> If anybody could help me here, it would be greatly appreciated. Thanks.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.