• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 236
  • Last Modified:

Preventing RequiredFieldValidator(s) from functioning on a specified portion of a form.

I have a page that has two "sections" (ASP.Net panels > > which render as HTML <DIV> blocks, anyway...).

One section is a "Login" section for existing users to login.  The other section is for new users to register (i.e. enter their name and create a password).

I've got required field validators on all my text boxes on the page.  However, there are two buttons:  one that fires the Logon routine, and the other that fires the Register routine.   By necessity, each button's CausesValidation property is TRUE.  What happens is that clicking either one of the buttons fires the validators for the whole page.

What I want is for the Login section's validators to "validate" only when the Login button has been clicked, and vice versa.  I would prefer to do all of the coding server-side in the code-behind and avoid JavaScript on this.

I've searched EE a bit on this already, but could find nothing that I liked (or even really addressed this type of issue).

My thought is that there ought to be a way to make the btnLogon_Click event's code "ignore" the other set of field validators.

The other idea that (I think) I understood from another EE post is to cause the validation to fire manually (make the buttons' CausesValidation property FALSE and raise the validation event elsewhere in the codebehind when I want it).  I'm not too crunk on how that ought to go down...
1 Solution
CausesValidation will not work for you if you must have both forms visible at the same time.

Good news is, you can achieve what you want with "ValidationGroups"
Bad news is that it is new in ASP.net 2.0, so unless you're developing the beta...

You may want to just use javascript to accomplish this...or, take the validation out of the login, if it's a simple username/password, it's quite simple to just deny the login if they don't enter a field...
mpp1031Author Commented:
Thanks, raterus.  That's essentially what I decided to do. ( btnLogin CausesValidation = false ).  Thanks for the help.

Featured Post

[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now