Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP .Net (http://www.velocityreviews.com/forums/f29-asp-net.html)
-   -   How do I use client-side validation with a custom validator? (http://www.velocityreviews.com/forums/t112691-how-do-i-use-client-side-validation-with-a-custom-validator.html)

Alan Silver 11-02-2005 11:20 AM

How do I use client-side validation with a custom validator?
 
Hello,

I have a custom validator on my page, and have the server-side code
working fine. I want to add a client-side funtion as well, but am not
sure how to wire it in so that it works with the other validators on the
page.

I specified the name of the Javascript function with the
ClientValidationFunction attribute of the custom validator, and it is
being called fine. However, if the validator returns false (ie bad
data), nothing happens on the client. With the other validators, I get a
message box popping up with the warnings, and I get the red text by the
control so the user can see which control fired the error.

How do I get the custom validator to do this? Here is the server tag...

<asp:CustomValidator ControlToValidate="txtDeliveryCountries"
OnServerValidate="ValidateTxtDeliveryCountries"
ClientValidationFunction="ValidateTxtDeliveryCount riesJS"
Display="Dynamic" Text="At least one country name does not start with
U_, E_ or W_" Runat="Server" />

(the point of the validator is that it checks a multiline textbox, that
is supposed to contain a list of countries, each of which has one of U_,
E_ or W_ as a prefix. The validator checks to make sure they didn't
enter a country without a prefix, or one with an invalid prefix).

TIA

--
Alan Silver
(anything added below this line is nothing to do with me)

Peter Blum 11-02-2005 07:45 PM

Re: How do I use client-side validation with a custom validator?
 
Hi Alan,

You wrote: "if the validator returns false". The definition of the
client-side validation function requires that you set the args parameter's
IsValid property to true or false:

function ValidateTxtDeliveryCountriesJS(source, args)
{
if (valid)
args.IsValid = true;
else
args.IsValid = false;
}

Note that names like args and IsValid are case sensitive.

--- Peter Blum
www.PeterBlum.com
Email: PLBlum@PeterBlum.com
Creator of "Professional Validation And More" at
http://www.peterblum.com/vam/home.aspx

"Alan Silver" <alan-silver@nospam.thanx> wrote in message
news:bOd8YWCmDKaDFwla@nospamthankyou.spam...
> Hello,
>
> I have a custom validator on my page, and have the server-side code
> working fine. I want to add a client-side funtion as well, but am not sure
> how to wire it in so that it works with the other validators on the page.
>
> I specified the name of the Javascript function with the
> ClientValidationFunction attribute of the custom validator, and it is
> being called fine. However, if the validator returns false (ie bad data),
> nothing happens on the client. With the other validators, I get a message
> box popping up with the warnings, and I get the red text by the control so
> the user can see which control fired the error.
>
> How do I get the custom validator to do this? Here is the server tag...
>
> <asp:CustomValidator ControlToValidate="txtDeliveryCountries"
> OnServerValidate="ValidateTxtDeliveryCountries"
> ClientValidationFunction="ValidateTxtDeliveryCount riesJS"
> Display="Dynamic" Text="At least one country name does not start with U_,
> E_ or W_" Runat="Server" />
>
> (the point of the validator is that it checks a multiline textbox, that is
> supposed to contain a list of countries, each of which has one of U_, E_
> or W_ as a prefix. The validator checks to make sure they didn't enter a
> country without a prefix, or one with an invalid prefix).
>
> TIA
>
> --
> Alan Silver
> (anything added below this line is nothing to do with me)




Alan Silver 11-02-2005 08:03 PM

Re: How do I use client-side validation with a custom validator?
 
>Hi Alan,
>
>You wrote: "if the validator returns false". The definition of the
>client-side validation function requires that you set the args parameter's
>IsValid property to true or false:


Yup, that was my sloppy explanation. Sorry about that.

>function ValidateTxtDeliveryCountriesJS(source, args)
>{
> if (valid)
> args.IsValid = true;
> else
> args.IsValid = false;
>}
>
>Note that names like args and IsValid are case sensitive.


I was setting args.Valid, not args.IsValid, which is why it didn't work.
I changed it and it worked fine.

Thanks very much

>--- Peter Blum
>www.PeterBlum.com
>Email: PLBlum@PeterBlum.com
>Creator of "Professional Validation And More" at
>http://www.peterblum.com/vam/home.aspx
>
>"Alan Silver" <alan-silver@nospam.thanx> wrote in message
>news:bOd8YWCmDKaDFwla@nospamthankyou.spam...
>> Hello,
>>
>> I have a custom validator on my page, and have the server-side code
>> working fine. I want to add a client-side funtion as well, but am not sure
>> how to wire it in so that it works with the other validators on the page.
>>
>> I specified the name of the Javascript function with the
>> ClientValidationFunction attribute of the custom validator, and it is
>> being called fine. However, if the validator returns false (ie bad data),
>> nothing happens on the client. With the other validators, I get a message
>> box popping up with the warnings, and I get the red text by the control so
>> the user can see which control fired the error.
>>
>> How do I get the custom validator to do this? Here is the server tag...
>>
>> <asp:CustomValidator ControlToValidate="txtDeliveryCountries"
>> OnServerValidate="ValidateTxtDeliveryCountries"
>> ClientValidationFunction="ValidateTxtDeliveryCount riesJS"
>> Display="Dynamic" Text="At least one country name does not start with U_,
>> E_ or W_" Runat="Server" />
>>
>> (the point of the validator is that it checks a multiline textbox, that is
>> supposed to contain a list of countries, each of which has one of U_, E_
>> or W_ as a prefix. The validator checks to make sure they didn't enter a
>> country without a prefix, or one with an invalid prefix).
>>
>> TIA
>>
>> --
>> Alan Silver
>> (anything added below this line is nothing to do with me)

>
>


--
Alan Silver
(anything added below this line is nothing to do with me)


All times are GMT. The time now is 06:00 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.