locked
Use JavaScript to get a control's ValidationGroup RRS feed

  • Question

  • User-1763871356 posted

    Hi,

    I'm trying to create a custom validator that will basically be a required field validator for multiple fields. To try to identify which fields to validate, I set the ValidationGroup property to a common name. The problem is I don't see how to get the ValidationGroup on the client side. When I look at the html markup that is rendered, I don't see my ValidationGroup name anywhere. Is it possible to get the ValidationGroup for a given control (e.g. a TextBox) on the client side? 

    Monday, March 1, 2010 8:41 PM

Answers

  • User-474980206 posted

    there isn't any. the validation group is applied to the validator itself via expando properties (see javascript at bottom of page). each postback control also has an optional validation group (passed via postback options), that used to determine which validators to run.

    you should add an expando property to the controls (or use a class name and a jquery like select) you want to validate. then your custom validator grop shoudl match the postback control.

    you could also switch to the jQuery validation library that already works the way you want.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, March 1, 2010 9:09 PM

All replies

  • User-474980206 posted

    there isn't any. the validation group is applied to the validator itself via expando properties (see javascript at bottom of page). each postback control also has an optional validation group (passed via postback options), that used to determine which validators to run.

    you should add an expando property to the controls (or use a class name and a jquery like select) you want to validate. then your custom validator grop shoudl match the postback control.

    you could also switch to the jQuery validation library that already works the way you want.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, March 1, 2010 9:09 PM
  • User-1763871356 posted

    Thanks Bruce. I've never heard of an expando property and have only heard of jquery but know nothing about it. I'll look into it. Do you know any good resources? 

    Tuesday, March 2, 2010 12:37 AM
  • User1364706731 posted

    To Validate a Specific Validator Group from JavaScript

    Page_ClientValidate(<<ValidationGroupName>>)


    Tuesday, March 2, 2010 12:50 AM
  • User-1763871356 posted

    Oh...JScript = javascript. My bad.

     

    Thanks pauldaniel, but I am referring to having the ValidationGroup set on input controls. I was trying to do custom validation without a bunch of validation controls. I ended up just doing required field validators for each field, then tying my form's submit button to a custom validator that calls a javascript method to do all my validation for me using Page_ClientValidate, my required field validator's group names, and some special logic.

    Tuesday, March 2, 2010 2:04 AM