2

I am performing both clientside validation and server side validation using jquery and Asp.net custom validator, required field validator.What i am doing is i display a 'X' next to the tetxbox which has wrong input.This is working fine , my issue is when a textbox has wrong input it shows 'X' as jquery validation function fires it , at the same time when he submits the data , custom validator also displays a 'X', so two 'X''X' are displayed like this, This kind of looks odd . So what can i do so that it is displayed properly , should i remove text from custom validator and only show error message on validation summary.any suggestions would be appreciated. Thanks

2 Answers 2

3

In my opinion keep using both, but just don't show 'X' on your jQuery validation. The Text attribute in the Custom Validator, will be seen in any case when submitting, and the ErrorMessage attribute on that validator, will appear in the summary. I have the same situation, and it works fine.

Hopefully, it helps you.

Sign up to request clarification or add additional context in comments.

8 Comments

thanks , if you are suggesting not to show 'X' on jquery then what is the alternative ,, any ideas
You're welcome. The alternative is to show your 'X' in the custom validator, when info is submitted. So just to be clear, custom validator exists when you want to validate situations that the other default validators can't do.
Hi again, if you still want to use jQuery and show something with it, you could e.g., trigger an alert box or set the background color of the wrong input field, in red.
,,, ya even m thinking of something like that ,, but the issue is currently i am displaying a label as 'X' and on hover of that 'X' it displays the title of the label as tooltip .. So i was wondering if i remove the label i could loose that functionality .
@Krystan Honour: Well, JQuery actually in integrated with asp.net. You can check some of the latest books on asp.net 4.0. Also the Microsoft certification for asp.net requires knowledge of JQuery. So if it is perfectly acceptable from Microsoft it shouldn't bother you.
|
3

The CustomValidator control has a property called ClientValidationFunction. This allows you to call a javascript method that has only one job - to set the IsValid property (of the args parameter) to true or false. The custom validator will take care of the error message for you. There is no need for you to have any jquery for showing and hiding the error. It should just work. Asp.net places some javascript on the page for this purpose so you don't have to.

Note: If you have a second RequireFieldValidator (or any other validator) for the same input, then be aware that you should set the Display="Dynamic" property which will ensure that the validator does not consume screen space while it is not being shown (which would cause your other validators messages to be pushed out of position).

For more details of the custom validators ClientValidationFunction property, see this page

I hope this helps

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.