1

I've a page with few textboxes and their corresponding validators (ASP.NET validator).

And clearly I can validate each of those validators from javascript by calling the function

Page_ClientValidate("myvalidators") 

where myvalidators is my validators group name

The same way I can validate a specific validator using

ValidatorEnable(Page_Validators[0]);

which only checks that specific validator

But my question is how can I find or figure out the control (Textbox) which is connected with that specific validator.

That means a function which can return all the controls with a failed validator.

Or more clearly, the function should return a collection object of controls where there corespnding validator is failed.

More description added

My scenario is to highlight the parent div of the textbox where the validator failed. So if I get the texbox control object or the control arrays, I can just take each of its parent div and can highlight it.

2
  • Showing the generated html will make it quite easy to understand Commented Feb 18, 2014 at 7:26
  • @Adil Does it require? Coz I specified the function I used to invoke the validator. Commented Feb 18, 2014 at 7:30

1 Answer 1

1

Page_Validators array returns the same metadata that we receive in custom validation function. It means that you can receive the associated control identifier something like this Page_Validators[0].controltovalidate.

 <script>
$(function () {
  // process all validators and their controls
  $.each(Page_Validators,function (i,v){ 
     if(v.controltovalidate) { 
        $("#"+v.controltovalidate); 
     } 
   });
});
</script>
Sign up to request clarification or add additional context in comments.

4 Comments

Sorry.. I think you misunderstood my scenario... Actually my requirement is, imagine my textbox id is txt1 and there is a requirefield validator assosiated with it. That validator I can refer as Page_Validators[0] So what my question is how we can get that txt1 object from using this reference Page_Validators[0]? Hope its clear now
Try this $("#"+Page_Validators[0].controltovalidate)
Thats awesome friend... Worked like a charm.. If you replace this with the answer given, I can mark it as right answer...
Ok. I replaced the answer

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.