Client-Side Validation with Validators and JavaScript

Discussion in 'ASP .Net' started by Nathan Sokalski, Feb 11, 2008.

  1. 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.
    --
    Nathan Sokalski

    http://www.nathansokalski.com/
    Nathan Sokalski, Feb 11, 2008
    #1
    1. Advertising

  2. Nathan Sokalski

    Manish Guest

    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


    "Nathan Sokalski" wrote:

    > 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.
    > --
    > Nathan Sokalski
    >
    > http://www.nathansokalski.com/
    >
    >
    >
    Manish, Feb 11, 2008
    #2
    1. Advertising

  3. 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.
    --
    Nathan Sokalski

    http://www.nathansokalski.com/

    "Manish" <> wrote in message
    news:...
    > 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
    >
    >
    > "Nathan Sokalski" wrote:
    >
    >> 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.
    >> --
    >> Nathan Sokalski
    >>
    >> http://www.nathansokalski.com/
    >>
    >>
    >>
    Nathan Sokalski, Feb 11, 2008
    #3
  4. Nathan Sokalski

    bruce barker Guest

    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)


    "Nathan Sokalski" wrote:

    > 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.
    > --
    > Nathan Sokalski
    >
    > http://www.nathansokalski.com/
    >
    >
    >
    bruce barker, Feb 11, 2008
    #4
  5. 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.
    --
    Nathan Sokalski

    http://www.nathansokalski.com/

    "bruce barker" <> wrote in message
    news:...
    > 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)
    >
    >
    > "Nathan Sokalski" wrote:
    >
    >> 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.
    >> --
    >> Nathan Sokalski
    >>
    >> http://www.nathansokalski.com/
    >>
    >>
    >>
    Nathan Sokalski, Feb 11, 2008
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Matt
    Replies:
    14
    Views:
    4,071
    Chad Z. Hower aka Kudzu
    Jan 30, 2004
  2. =?Utf-8?B?dmlkeWE=?=
    Replies:
    1
    Views:
    740
    Kevin Spencer
    Jun 2, 2005
  3. Stuart Whiteford
    Replies:
    2
    Views:
    734
    Stuart Whiteford
    Apr 25, 2006
  4. Boss302
    Replies:
    0
    Views:
    1,020
    Boss302
    Nov 21, 2006
  5. Nathan Sokalski

    Client-Side Validation with Validators and JavaScript

    Nathan Sokalski, Feb 11, 2008, in forum: ASP .Net Building Controls
    Replies:
    4
    Views:
    903
    Nathan Sokalski
    Feb 11, 2008
Loading...

Share This Page