Displaying validator error message only after validation fails

H

Helen

Hi

I'm using ASP.NET's standard validators to display error messages when
people don't fill in required fields on my form.

The error messages currently show as soon as the form is loaded, but
what I'd really like is for the error messages to only be displayed
after the validation fails. Is this a feature of the standard ASP.NET
validation or will I have to write custom validators if I want to do
that?

Helen
 
R

Rutger Smit

Helen said:
Hi

I'm using ASP.NET's standard validators to display error messages when
people don't fill in required fields on my form.

The error messages currently show as soon as the form is loaded, but
what I'd really like is for the error messages to only be displayed
after the validation fails. Is this a feature of the standard ASP.NET
validation or will I have to write custom validators if I want to do
that?

Helen


For the submit button/link, set the CauseValidation to False.
The, in the onclick event of the submit button, call Page.Validate
followed by if(!Page.IsValid){return;}

Got it?

--

//Rutger

DoDotNet@KICKTHIS_Gmail.com
www.RutgerSmit.com
 
H

Helen

Thomas Dodds said:
Use the Text property instead of the ErrorMessage property ...

I've tried:
<asp:requiredfieldvalidator id="FirstNameRequiredfieldvalidator"
runat="server" ForeColor=" " errormessage="Please enter your first
name" controltovalidate="FirstNameField" display="dynamic">This field
is required</asp:requiredfieldvalidator>

<asp:requiredfieldvalidator id="FirstNameRequiredfieldvalidator"
runat="server" ForeColor=" " errormessage="Please enter your first
name" controltovalidate="FirstNameField" display="dynamic" text="This
field is required"></asp:requiredfieldvalidator>

<asp:requiredfieldvalidator id="FirstNameRequiredfieldvalidator"
runat="server" ForeColor=" " errormessage="Please enter your first
name" controltovalidate="FirstNameField" display="dynamic" text="This
field is required"</asp:requiredfieldvalidator>

<asp:requiredfieldvalidator id="FirstNameRequiredfieldvalidator"
runat="server" ForeColor=" " controltovalidate="FirstNameField"
display="dynamic" text="This field is
required"></asp:requiredfieldvalidator>

<asp:requiredfieldvalidator id="FirstNameRequiredfieldvalidator"
runat="server" ForeColor=" " controltovalidate="FirstNameField"
display="dynamic" text="This field is
required"></asp:requiredfieldvalidator>

<asp:requiredfieldvalidator id="FirstNameRequiredfieldvalidator"
runat="server" ForeColor=" " errormessage="Please enter your first
name" controltovalidate="FirstNameField" display="dynamic" text="
"></asp:requiredfieldvalidator>

Helen
 
P

Peter Blum

Hi Helen,

The error messages should not appear when the form is first loaded. They
should appear:
- after edits reveal errors
- when the user clicks Submit and client-side validation detects errors
- when the page is posted back with errors and the Page.Validate() method
runs (which occurs automatically in your submit button's Click method unless
CausesValidation=false)

You can cause them to appear when the form is first loaded in these ways:
- You call Page.Validate() even when there is a new page.
- You call the Click method on a button that has CausesValidation=true
- You have some client-side javascript that knows how to run the Microsoft's
validation code. It runs as the page is loaded.

I hope this helps!

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

Helen

Hi Peter

Thanks for your help. :) I found the problem. One of my User Controls
was calling Page.Validate() in the page load method because the way I
originally did the validation error messages was different.

BTW we're using your date package on the site and it's been really
useful (I usually hate anything to do with dates).

Helen
 

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,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top