473,390 Members | 1,643 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,390 software developers and data experts.

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
5 3052
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Stephan Bour | last post by:
Hi, I have a regular expression validator that checks a text box string: <asp:RegularExpressionValidator id="SeqFormat" runat="server" Display="Static" ErrorMessage="Your sequence contains...
2
by: Lucas Tam | last post by:
Hi all, I want to display an error message from a custom validator in my Validation Summary control. Do I need to build the ServerValidate Event handler in order to display an error...
2
by: Dot net work | last post by:
Hello. Say I have a .net textbox that uses a .net regularexpressionvalidator. If the regular expression fails, is it possible to launch a small client side javascript function to do something,...
5
by: darrel | last post by:
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...
6
by: Paul | last post by:
I am trying to setup a field validator and tried using the control to validate set to a dropdown list box but did not seem to work. Is there anyway to set this up or do you need to use client side...
2
by: SimonH | last post by:
Hi All, I'm having problems getting a custom validator to work. I'm hoping someone could perhaps notice what I've missed. I only want to provide a server side validation method. The problem is...
8
by: pmud | last post by:
Hi, I am using a compare validator in asp.net application(c# code). This Custom validator is used for comparing a value enterd by the user against the primary key in the SQL database. IF the...
3
by: Tumurbaatar S. | last post by:
I'm trying to dynamically hide/show a HTML table server control. My form contains one CheckBox control and its AutoPostBack set to true. The Checked value of this box controls whether to show or...
8
by: Radu | last post by:
Hi. I have an ASP control on my page: <asp:Calendar ID="calStart" ................ Etc </asp:Calendar> and I have a Custom Validator defined as <asp:CustomValidator
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.