asp .net for validation question

M

Matt Mercer

Hi,

My first post here. I am a self-taught, very "green" web developer. It
is not the main focus of my job but required from time to time.

I am developing a web application that logs security incidents for my
company. Here is a little background on how it works. I am using ASP
..net and VB. The user first submits a new incident which has several
required and not required fields related to the incident. The new
incident is written to a SQL table. The primary key number is then
cached and the user is taken to a place where he/she can submit
people, properties, or attachments to go with this incident. These are
not required. (i have a feeling maybe this is bad design). So I have
one form with four submit buttons. One for incident, person, property,
and attachment. My problem is this:

When I use asp .net built in data validation it appears to validate
all the fields that come before the submit button I am using. So when
I submit an incident it doesn't flag me for say, a person's name being
blank because this is later in the form. If a user does not want to
enter a person, but wants to enter a property, he/she gets an error
that he did not put a name in for the person. I don't want this to
happen. The name is only required if a person is submitted.

I would like to know if there is a way to do this with the built in
validation on the same form? One of my requirements was to do this all
on one page, and the incident has to be submitted before I can add
people, properties, and attachments to it.

Whew....hope that makes sense. Thanks in advance.
 
M

Mark Harris

Set all your validators to server side only and disabled, then depending
on which form is submitted enable those validators with your code - once
this is done call Page.Validate() and then you can check Page.IsValid ;)

Additionaly you may wish to use some div tags that "runat" "server", then
you can hide the form areas that are not able to be submitted when they
are creating the incident, and then hide the incident form once they have
submitted it - showing the second stage.


- Mark
 
P

Peter Blum

It sounds like you need the feature called "validation groups" which is
coming in ASP.NET 2.0 (due in Spring of 2005 and available today in Beta 1
from Microsoft). This allows you to assign a group name to each button and
the validators it fires.

Without it, the description given by Mark Harris makes sense: validating on
the server side only. I recommend leaving validators enabled. Instead, I
recommend in the Click event for each button, call the Validate() method on
individual validators that are involved. Then test each validator's own
IsValid property and continue if all are true.

I offer a commercial solution for this problem that provides validation
groups and works fully on the client side: "Professional Validation And
More" (http://www.peterblum.com/vam/home.aspx).

There are many limitations in Microsoft's validator controls. I've put
together a list of them at http://www.peterblum.com/vam/valmain.aspx to help
people plan their validation designs.

--- 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,796
Messages
2,569,645
Members
45,371
Latest member
TroyHursey

Latest Threads

Top