Getting the Names/Labels of form fields that are invalid.

D

darrel

I have a form that has validators for each field. When I submit the form, if
the field is invalid, it shows an error next to the field. Works perfectly.

I also have a label at the top of the form that, if page is NOT valid, will
display. This message says 'there is a problem with the form, please fix the
fields below'.

What I'd like to do is have that message also state which of the fields were
invalid.

I can use a summary validator for that, but that is rather cumbersom in
terms of layout, so I'd like to write out my own message/formatting. Is
there a way to 'get' values from fields that weren't valid?

I imagine I need to call a function, have that function check that validity
of each field, and then have that return a string?

-Darrel
 
P

Peter Blum

You can definitely build a custom control that looks through the validation
data. You have to build client-side and server-side support for it.
On the server side, the Page.Validators collection contains the validators.
Each has its own IsValid property that when false, indicates an error.
On the client-side, the Page_Validators array contains a list of HTML
elements (<span> tags) that are the actual validators. Look at the script
file \aspnet_client\system_web\[version]\WebUIValidation.js to study how to
use each element and detect that its valid.

I have built a replacement to Microsoft's validation system. It includes a
much more flexible ValidationSummary control with several new formatting
choices. If you drop me an email describing how you would like to format
your ValidationSummary, I can tell you if and how it works with my software.
("Professional Validation And More" at
http://www.peterblum.com/vam/home.aspx)


--- 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

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,898
Latest member
BlairH7607

Latest Threads

Top