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.

Sandeep Thomas
  • 4,303
  • 14
  • 61
  • 132

1 Answers1

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>
Michael
  • 1,453
  • 3
  • 20
  • 28
  • 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 – Sandeep Thomas Feb 18 '14 at 09:21
  • 1
    Try this $("#"+Page_Validators[0].controltovalidate) – Michael Feb 18 '14 at 09:32
  • Thats awesome friend... Worked like a charm.. If you replace this with the answer given, I can mark it as right answer... – Sandeep Thomas Feb 18 '14 at 09:57
  • Ok. I replaced the answer – Michael Feb 18 '14 at 10:09