Ways to validate form before submitting

W

Wysiwyg

I need to validate a form to ensure that all of the fields add up correctly.
I can't do this while the user is entering data since validation needs to be
done after the entry is completed. What's the "best" way to validate prior
to submitting?

I could add an onsubmit attribute to the form which executes the validation
in Javascript. That way the response doesn't need to be sent before
validation takes place. Is this pretty much the way to do it?

Thanks!
Bill
 
I

IPGrunt

I need to validate a form to ensure that all of the fields add up correctly.
I can't do this while the user is entering data since validation needs to be
done after the entry is completed. What's the "best" way to validate prior
to submitting?

I could add an onsubmit attribute to the form which executes the validation
in Javascript. That way the response doesn't need to be sent before
validation takes place. Is this pretty much the way to do it?

Thanks!
Bill

Bill,

You could hook the onchange event in JS, but ASP.NET WebForms have built in
validation controls, meant to check existance, regular expressions, etc.

There is also a custom validator control designed for you to place your own
code, ie, to check for disallow characters, a particular input format, etc.

The ASP.NET framwork takes care of when to fire, and manages the flow of
control for you. All your validator has to do is set an IsValid field to true
or false.

Check this out. Very slick indeed!

-- ipgrunt
 
W

Wysiwyg

I'm already using all of those types of validation on individual fields.
When individual fields are updated the displayed subtotals update with
client code set up with the custom validators, the number ranges are
checked, etc. However, an onchange event doesn't help when I need to
evaluate the data after the user has finished entry. There's no point in
validating whether or not the data adds up if the user hasn't finished
entering it yet.

I need to validate the entire form right before it is submitted. I'm looking
for ways to validate the form as a whole and not individual fields.

Bill
 
I

IPGrunt

I'm already using all of those types of validation on individual fields.
When individual fields are updated the displayed subtotals update with
client code set up with the custom validators, the number ranges are
checked, etc. However, an onchange event doesn't help when I need to
evaluate the data after the user has finished entry. There's no point in
validating whether or not the data adds up if the user hasn't finished
entering it yet.

I need to validate the entire form right before it is submitted. I'm looking
for ways to validate the form as a whole and not individual fields.

Bill

Thanks for explaining. I guess I missed an earlier question?

Anyway, you sound like you've thought about this and are on the right track
toward doing what's required.

BTW, there is a validator summary control. Perhaps there's an event you can
hook that makes sense for your need?

Good luck.

-- ipgrunt
 

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,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top