Please help. Validate only selected controls

  • Thread starter Thread starter Paul
  • Start date Start date
P

Paul

Hi,

I hope somebody can help me with the following. (I have tried
searching for a solution on the newsgroups but nothing is quite what I
need. Feel free to point me in the direction of anything I may have
missed though.)

I have a form with 2 text boxes, two list boxes and 2 buttons (A & B).
Both buttons must perform some validation but they differ in their
extent. Button A must ensure that a date has been entered in both text
fields and that at least one item has been selected in one of the list
boxes (it is always the same one). Button B however must ensure that a
date has been entered in both text fields and that at least one item
has been selected in each list box. Button A serves to populate the
other list box based on the values in the text boxes and the selected
item in the list box. Button B serves to submit the form when it is
totally complete.

I have added the necessary validation controls (i.e. combination of
RequiredFieldValidators, RangeValidators and CompareValidators) to my
form so that all fields are validated when Button B is clicked. What
can I do so that if Button A is clicked that only the text boxes and
one list box is validated. The EnableClientScript property of each
validation control is true so the form is validated client side and
this is something I'd like to maintain. I'm using a validation summary
control to display error messages.

Any help would be appreciated.

TIA

Paul
 
This sounds like a case where you need ASP.NET 2.0's "Validation Groups".
You would define unique names for each group of validators that you want to
fire. Assign those names to the Groupname property on validators and the
buttons. Yet, ASP.NET 2.0 will not be shipping for a while. Don't give up
hope though. Validation Groups is available in commercial validation
products. Mine is "Professional Validation And More" at
http://www.peterblum.com/vam/home.aspx.

--- Peter Blum
www.PeterBlum.com
Email: (e-mail address removed)
Creator of "Professional Validation And More" at
http://www.peterblum.com/vam/home.aspx
 
Hi Peter,

I look forward to being able to use validation groups when we upgrade
to ASP 2.0.

I did get around this in the end by setting the CausesValidation
property of Button A to false then adding javascript that would get
executed on its click event

ButtonA.Attributes.Add("onClick", "return validateForm();")

The javascript would only validate certain controls. It used many of
the functions and objects present in the mini-API that you can use on
the client, for example ValidatorValidate, ValidatorEnable,
Page_IsValid, Page_Validators etc.

On the server side I just disabled certain validation controls before
calling the page validate method.
 
Back
Top