467,077 Members | 1,037 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,077 developers. It's quick & easy.

Displaying validator error message only after validation fails

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
Nov 18 '05 #1
  • viewed: 2812
Share:
5 Replies
Helen wrote:
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
Nov 18 '05 #2
Use the Text property instead of the ErrorMessage property ...
"Helen" <he***@helephant.com> wrote in message
news:33*************************@posting.google.co m...
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

Nov 18 '05 #3
"Thomas Dodds" <th*********@hotmail.com> wrote in message news:<OY**************@TK2MSFTNGP09.phx.gbl>...
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
Nov 18 '05 #4
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: PL****@PeterBlum.com
Creator of "Professional Validation And More" at
http://www.peterblum.com/vam/home.aspx

"Helen" <he***@helephant.com> wrote in message
news:33*************************@posting.google.co m...
"Thomas Dodds" <th*********@hotmail.com> wrote in message
news:<OY**************@TK2MSFTNGP09.phx.gbl>...
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

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

Peter Blum wrote:
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: PL****@PeterBlum.com
Creator of "Professional Validation And More" at
http://www.peterblum.com/vam/home.aspx

Nov 18 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Stephan Bour | last post: by
2 posts views Thread by SimonH | last post: by
3 posts views Thread by Tumurbaatar S. | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.