473,729 Members | 2,185 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How do I suppress the display of validation messages

I have a web control that takes a date input. There are two types of
validation I want to do on this:

1) validate that the date input is in the proper format, and display a
message if otherwise
2) validate that the date is not prior to today, and display a message if

For these validations, I use CompareValidato r to ensure the date is not
prior to today, and RegularExpressV alidator to ensure the date is in the
proper format (mm/dd/yyyy).

However, it appears that both of these validators fire and display. So, if
the user enteres in a bogus date (ABCDEFG), they get both the error message
that the date is in the improper format AND that the date is prior to today.

If the date isn't formatted corretly, I don't want the "prior to today"
validation to fire. But I can't seem to do that, and my page always displays
both error messages.

Is there any way to do this?
May 25 '06 #1
3 2617
Use 2 validators.

May 25 '06 #2
Thanks for the reply, but unfortunately I'm not quite sure what you mean. I
mean, I am using two validators, but the problem is both are displaying their
error messages and I only want the first error to display. For example, here
is the code:

<asp:RegularExp ressionValidato r
ID="MyDateRegul arExpressionVal idator"
ControlToValida te="MyDateTextB ox"
ValidationExpre ssion="(0?[1-9]|1[012])[- /.](0?[1-9]|[12][0-9]|3[01])[-
Display="Dynami c"
Text="Improper date">
</asp:RegularExpr essionValidator >

<asp:CompareVal idator
ID="MyDateAfter TodayCompareVal idator" runat="server"
ControlToCompar e="TodaysDateTe xtBox"
ControlToValida te="MyDateTextB ox"
Display="Dynami c"
Operator="Great erThanEqual"
Text="Date is prior to today">
</asp:CompareVali dator>

If I enter "asdf" in the field, the web page displays two error messages:

Improper date
Date is prior to today

I want it to stop after displaying "Improper date" and not display "Date is
prior to today".
May 25 '06 #3
i would suggest doing custom validation instead of using the validation
that ASP.NET provides. Here is a sample of a date validator.

private bool ValidateDate(st ring Date, Label ErrLabel)
bool DateIsValid = false;
ErrLabel.CssCla ss = "ErrMsg";
ErrLabel.Text = string.Empty;
string DateRegex =

//check to see if format is correct
if(FormatValid( Date, DateRegex))
DateTime.Parse( Date);
DateIsValid = true;
{ ErrLabel.Text = "Format: 'MM/dd/yyyy'"; }
ErrLabel.Text = "Format: 'MM/dd/yyyy'";

return DateIsValid;

May 25 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

by: James | last post by:
Hello, I have a RequiredFieldValidator for several textbox controls on a form. Here's an example with the RequiredFieldValidator. EnableClientScript, Enabled, and Visible are set to true for the RequiredFieldValidator. <asp:textbox id="FirstName" MaxLength="25" runat="server"></asp:textbox>
by: Milan | last post by:
Hi, I am having a problem with displaying a * to a required field. There seems to be a problem with this and the static value does not appear unless you submit the page. I am trying to display the static text as soon as the page is loaded in the browser. Does anyone know if there is a bug with the aps.net validator controls? Or is this not possible.
by: Dan Sikorsky | last post by:
Even though the documentation says the default color of the validation summary message display color is red, my color is showing black. I've even set the ForeColor attribute in the asp:validationsummary tag to red, but it still shows black. How can I resolve this?
by: c676228 | last post by:
Hi, I have several user controls like email, phone,ssn etc. each has it's own validation message in its user control already. When I bring all those user controls in an aspx page, I would like to display a summary error messages using validation summary in an aspx page, how to do that? Thank you. -- Betty
by: FayeC | last post by:
Can anybody point me to a good tutorial/manual on advanced server-side form validation including validation of fields against unwanted strings such as the use of "http://". Thank you in advance, FayeC
by: Rik | last post by:
Hello guys, now that I'm that I'm working on my first major 'open' forms (with uncontrolled users I mean, not a secure backend-interface), I'd like to add a lot of possibilities to check wether certain fields match certain criteria, and inform the user in different ways when the data is wrong (offcourse, this will be checked on posting the data again, but that's something I've got a lot of experience with). Now, offcourse it's...
by: gweasel | last post by:
What is the best way to apply a Validation Rule - or rather, where is the best place to put it? Is there an advantage to putting it on the field in the table vs setting the validation rule on the form the control is on? Basically I have a number of controls in a form that are required, and to check it I am setting the Validation Rule to "<>"IsNull" so that when the user tries to tab through/click out of a required area without entering...
by: jaishu | last post by:
When i try to insert data into a backend Oracle table (with ODBC) using a form, (i use docmd.runsql "insert....") Access gives me a message like"You are trying to append 1 row to the table are you sure you want to append?" i want to suppress this message as i have to insert into 2 tables and delete from 3 tables when the user enters some data in the form, so it asks the user five times (say 2 times for insert and 3 times for delete..) when...
by: ZeeHseez | last post by:
Hi, I have written a webbrowser application in VB .net Framework 1.1. I would like to suppress javascript error messages. However, the silent property of the webbrowser control suppresses the Javascript messages, but it also blocks any other dialog box, such as Login dialog, i can't use the silent property. I used http://support.microsoft.com/default.aspx?scid=kb;EN-US;279535 article to suppress the error messages. It works fine until a...
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.