Thursday 15 April 2010

javascript - How to set custom validator isValid property on Client Side? -


I'm having trouble setting customvalidator on the client side, depending on the value of a particular hidden area, on a button Click the Clutter event function to be firing, which considers the incorrect property of the custom validator incorrect.

Below is some code: Code Back:

  Protected Zero Page_Old (Object Sender, EventArgse E) {If (hidden version == true) {btnSend.OnClick = "SomeJavascriptFunction ()"; ASPX file:   functions> someJavascriptFunction () {if (hiddenfieldValue == true) // Show certification and do not postback vldValdiator.isValid = false; return false; // Do not postback second truth back; Do Postback} & lt; Asp: CustomValidator id = "vldValidator" runat = "server" text = "ABC" />   

I am not able to set the isValid property on client side based hidden values. Please help . thank you in advanced.

method 1

You can click on the ClientClick event button Within Page_IsValid can attempt to set the property incorrectly, it can not validate the page in that case unless the asp.net assumptions are concerned.

Original example

  Click the Function button) Click on the "If ($ ('# hiddenFieldID'). Val () == 'someValue') {Page_IsValid = false; }}   

Honestly - I am not sure that Page_IsValid property will not be reset. You will need to try.

Method 2

You can check the customvalent client verification in the hidden area and pass it to the validator or On that basis, recognition can fail. Click on the button, the event can again call the Page_ClientValidate () function which will force verification on the page. This will then set the correct verification property.

Basic example 2

  function CustomValidatorClientValidate (source, argument) {if ($ ('(# HiddenFieldID'). Val () = = 'Some values') {arguments.IsValid = true;} and {arguments.IsValid = false;}} ButtonOnClientClick () {Page_ClientValidate ();}   

This uses JQuery It is because - I find it easy to write an example like this: It does not make sense to use it, besides this, I am assuming the ASPN Vedicator API. It should be, if you have included those controls But by adding a check for the function names you can always be tough

ALSO

If you are using the Verification Group, which you will probably call < Previous> Page_ClientValidate (validationGroupName);

Method 3

You can try about it but isvalid of customvalidator You can set the property, this should give you more direct control of validity, the context you want below

isvalid boolean contact The Ti. This is a property on each customer verifier, which indicates that it is currently valid

I did something like this before, but I personally have not tried it.

In general

The method you are using in general is using JavaScript API that uses asp.net validators. But you want control that you want

context

This gives a reference to the JavaScript API you are trying to use. This is a long article, but the bit you want is about half way

more

> I really have to leave it but your code is wrong here - it's OnClientClick. btnSend.OnClientClick = "Some JavaScript Functions ()";

No comments:

Post a Comment