Displaying a message contigent on another validator.

D

darrel

I'm using some validators for a form. If the field is invalid, the page
reloads with the error next to the field.

This works, and I like it.

I'd also like to add a separate message to the top of the page along the
lines "there appears to be an error with your submission. Please check the
form below. Items to correct appear in RED".

What would be the best way to do this? I was thinking that I could just wrap
it in a panel and set it to visible/hidden based on the validators. Is there
a way to check for ANY validator error? Something like:

if any validator = error, then panel.visibility = true

-Darrel
 
A

Andrew Jones

Try ValidationSummary.
I believe this is designed exactly for this purpose.
(Only been coding .NET for 1 week now though)
:)

AJ
 
D

darrel

look at the Validation Summary control

Curt/Andrew:

THANKS!

Unfortunately, once again, this seems to be a control that doesn't QUITE
give me the flexibility I need.

I want to have a custom error at the top, with the specific errors showing
up at each field (with their own validator controls). I can add custom text
in the validationSummary using the HeaderText attribute. However, it insists
on also showing the errorSummaries. I can turn off the errorSummaries, but
that also turns off the HeaderText.

So not *quite* what I was working for.

Any other suggestions?

-Darrel
 
P

Peter Blum

Let's try a different approach.

Add a label to the page that has the desired text.
When IsPostBack=false, set its Visible property to false
When IsPostBack=true, set its Visible property according to the Page.IsValid
property. Do this after Page.Validate() has run (usually your post back
event handler).

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

Andrew Jones

Here is one I'm using:

<asp:customvalidator id=CustomValidator2 style="Z-INDEX: 111; POSITION:
relative;
TOP: 20px" runat="server"
ErrorMessage="New Password Must Contain Both Letters and Numbers"
EnableClientScript="False"
OnServerValidate="checkNewPass">*</asp:customvalidator>

Notice the * between the tags. This text will appear wherever you place
this validator on your page.
The Error Message only goes to the summary.

AJ
 

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,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top