2

Here's a curious case: I have a form with several data-input controls on it. A sub-set of these controls can be shown / hidden by checking a checkbox. All controls and their associcated Validators belong to a ValidationGroup called "Advanced", as does the asp:Button Submit button and a ValidationSummary.

The thing is, I don't want the sub-set of fields to be validated if they are hidden; they are only required if they are visible.

A really unpleasant way of doing it would be to have another asp:button that gets shown / hidden along with the extra fields, and the normal submit button gets show / hidden, but add in another couple of sub-sets of fields and it gets a bit messy...

Any thoughts? Would dearly love to stick with my tried and trusted Validation controls...

Thank you,

Mike K.

2 Answers 2

1

Can you set it up so that when you set the fields to "hidden" you also Disable the validation?

protected void chkBoxChecked(object sender, Eventargs e) {
     validationControl.Enabled = false;
}

Of course you would need to make sure that our checkbox had it's AutoPostBack property set to True;

If you want to avoid using Postback/Flash, of course you could probably wrap the whole thing in an UpdatePanel, or you could do it all in javascript:

Using Javascript to disable validators

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

2 Comments

It's all done with JavaScript (as opposed to smoke and mirrors), as an attempt to minimise PostBack.
0

See this question. You should disable the validators when the controls they validate are hidden. The two answers show how to disable the validators on the client side and on the server side.

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.