473,763 Members | 1,312 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Ways to validate form before submitting

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
Nov 19 '05 #1
4 4285
Hi Bill:

The best approach would be to use a custom validator.

http://msdn.microsoft.com/library/de...torcontrol.asp

This approach will work with the validation framework in ASP.NET and validate
the page client side (with script) before the form posts back to the server
(and validates on the server side as well).

--
Scott
http://www.OdeToCode.com/blogs/scott/
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

Nov 19 '05 #2
"Wysiwyg" <wy*****@xmissi onNSPAM.com> confessed in news:ct6man$v5c $1
@news.xmission. com:
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
Nov 19 '05 #3
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

"IPGrunt" <me@privacy.net > wrote in message
news:Xn******** *************** ***********@130 .133.1.4...
"Wysiwyg" <wy*****@xmissi onNSPAM.com> confessed in news:ct6man$v5c $1
@news.xmission. com:
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

Nov 19 '05 #4
"Wysiwyg" <wy*****@xmissi onNSPAM.com> confessed in news:ct8evp$89g $1
@news.xmission. com:
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

"IPGrunt" <me@privacy.net > wrote in message
news:Xn******** *************** ***********@130 .133.1.4...
"Wysiwyg" <wy*****@xmissi onNSPAM.com> confessed in news:ct6man$v5c $1
@news.xmission. com:
> 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



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
Nov 19 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

19
2999
by: Pete | last post by:
I have form/select which executes a function using onchange. No problem. However, when I validate the page with a strict HTML 4.01 doctype at http://validator.w3.org, it demands either an action or a method for the form?. If I give it an empty action <form action="" ..... it validates OK. Is this acceptable or is there a better/standards correct way? Thanks.
5
5402
by: Kit | last post by:
Hi there, I am recoding a website, and I want to add a generic footer to each page, using an included file with PHP snippets. Part of that footer would be a link to validate the page using the W3C's validation service. The code currently looks like this: <code> <a href="http://validator.w3.org/check?uri=<?php echo "http://www.athenatest.org" . $PHP_SELF; ?>" >
15
6576
by: M Smith | last post by:
I have a form I want to submit to itself. I want to be able to type in a list of numbers and submit the form and have that list show up on the same form under the text box I typed them into and the buttons. The problem is when I post a form to itself, the Enter key will not submit the form, it only clears the contents of the text box. The only way I can submit is to click the submit button. Here is a simplified version of my code that I...
1
1973
by: Johnny | last post by:
Hello, I've read somewhere that you can validate form data before actually submitting it, similar to what validation controls would do. For example, I have a form that has 2 textboxes. I populate the 2 textboxes with values from the database. I also have an update button that will update the values. If I have not made any change to the data in the textboxes, then I do not want to submit the data when the update button is clicked. I...
9
6697
by: B-Dog | last post by:
I have a form that has about 10 text boxes on it, they all have to be filled out before submitting is there a quick way to make sure that none are null or do I have to call out each textbox? Say something like textbox1 through textbox10? Thanks
2
2228
by: juventusaurabh | last post by:
I have a form with a number of fields, some of which would be filled(populated) automatically from the MS SQL database on certain event.Now, I have certain validations on the fields from sql database as constraints(eg. format of the tel number), So I was wondering how do I catch these runtime exceptions which r likely to occur if the user enters something which violated the sql constraints. Also, on my form, the user can also change the...
2
2054
by: Bob | last post by:
I know how to use php/mysql, but the html aspect of what Im trying to do (if its even possible this way) is what Im unsure of. I want to have a button that a user can hit to valid mysql info before submitting the full page of info. I know this doesnt work, but something like the following: <form method=POST action="http://mysite.com/send.php"> <input type=text name=user>
3
2301
by: Jeff | last post by:
I know how to use php/mysql, but the html aspect of what Im trying to do (if its even possible this way) is what Im unsure of. I want to have a button that a user can hit to valid mysql info before submitting the full page of info. I know this doesnt work, but something like the following:
8
11790
by: chandhseke | last post by:
I have a form with various fields, one of which I need to check against data in a database table. i.e if the value entered into the text input field exists in the database, the form should be submitted normally; otherwise an error message should be issued without submitting the form. How can I achieve this kind of validation? Thanks
0
9563
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10145
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9938
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9822
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8822
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5270
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5406
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3917
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2793
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.