Blog

ATAYE HOME Blog Home Account Search
Using Clientside Validator

Hello,

To use the client side validator you first need to add one to your page.  Then in html view add a new javascript method as follows: (Im using the dotnet v2.0)

<script type="text/javascript">
function
ValidateClientItem(sender, args)
{
    var
sMyVal = args.Value;

    if (sMyVal != sValidString
)
    {
        args.IsValid = false
;
        return
;
    }
    args.IsValid = true
;
}
</script>

Then, set the ClientValidationFunction property of the custom validator to the name of the function, in this case 'ValidateClientItem'.  You dont need to set ControlToValidate if you dont want, but you wont be able to use args.Value.

Thats all there is to it.  When the client form is submitted, the validator is called and will in turn call your client side javascript method.  Setting args.IsValid to false cancels the form submit and displays the validator error message.

Happy coding,

James


 
copyright 2007 Ataye.com.au