validating only a part of the form

J

Joe Abou Jaoude

hi
I m facing the following problem often :
In a web page the user can click on 2 buttons "button1" and "button2".
If the user clicked on button1 then I have to validate part of the form
(some controls musn't be validated), and if the user clicked on button2
then I have to validate the other part of the form.
Usually I would do this by using one custom validator (for all the web
page) that detects the button that has been clicked and perform
validation. In this way, I m writting the validation using javascript
code. I managed to do this before however now I m facing more and more
complicated validations, so I was wondering if there's a way to disable
some validators according to the button that has been clicked.

Regards
 
P

Peter Morris [Droopy eyes software]

Hi

Sounds to me like your design is wrong :) Can't you have two different
forms instead of one form with two purposes?

Instead of using validators you could validate the form using code in
the button, I have written an article about adding errors at runtime here...

http://www.howtodothings.com/ViewArticle.aspx?Article=660


--
Pete
====
ECO Modeler, Audio compression components, DIB graphics controls,
FastStrings
http://www.droopyeyes.com

Read or write articles on just about anything
http://www.HowToDoThings.com

My blog
http://blogs.slcdug.org/petermorris/
 
B

Brock Allen

In ASP.NET 1.x Validation is page-wide. One thing you can do is to set one
of the Button's CausesValidation property to false.

In ASP.NET 2.0 they have the ability to have ValidationGroups which allows
different regions of validation on a single page.
 
W

William F. Robertson, Jr.

Not yet, but is ASP.NET 2.0, they have added validation groups that buttons
will only validate certain input fields, for now you will need to come up
with a solution on your own. You could always cheat and only have server
side validation.

What I do, or rather used to do, is decide the most complicated validation
button, set the validation for that button and input controls. I will
manually check the smaller validation set manually solely in code behind and
set CausesValidation to false for the "easy" button.

bill
 
P

Peter Blum

Hi Joe,

Validation groups are available in third party replacements to the ASP.NET
validators.
I created "Professional Validation And More"
(http://www.peterblum.com/vam/home.aspx) to address a large list of
limitations and missing features in validation. Each of my 22 validators
supports "validation groups" and my client-side validation works on far more
browsers than the original validators do. My validators also have the
ability to smartly enable themselves based on setttings on the page, like if
a checkbox is checked, then the validator is enabled. You will find
extensive improvements on how validators and the ValidationSummary control
communicate with the user, like changing the color of the field with the
error and offering a hyperlink on each error message in the
ValidationSummary to jump to the field with the error.

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top