473,395 Members | 2,222 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,395 software developers and data experts.

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
otherwise.

For these validations, I use CompareValidator to ensure the date is not
prior to today, and RegularExpressValidator 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 2606
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:RegularExpressionValidator
ID="MyDateRegularExpressionValidator"
runat="server"
ControlToValidate="MyDateTextBox"
ValidationExpression="(0?[1-9]|1[012])[- /.](0?[1-9]|[12][0-9]|3[01])[-
/.](19|20)\d\d"
Display="Dynamic"
Text="Improper date">
</asp:RegularExpressionValidator>

<asp:CompareValidator
ID="MyDateAfterTodayCompareValidator" runat="server"
ControlToCompare="TodaysDateTextBox"
ControlToValidate="MyDateTextBox"
Display="Dynamic"
Operator="GreaterThanEqual"
Type="Date"
Text="Date is prior to today">
</asp:CompareValidator>

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(string Date, Label ErrLabel)
{
bool DateIsValid = false;
ErrLabel.CssClass = "ErrMsg";
ErrLabel.Text = string.Empty;
string DateRegex =
@"^(0[1-9]|1[0-2])/(0[1-9]|[12][0-9]|3[01])/\d{4}$";

//check to see if format is correct
if(FormatValid(Date, DateRegex))
{
try
{
DateTime.Parse(Date);
DateIsValid = true;
}
catch
{ ErrLabel.Text = "Format: 'MM/dd/yyyy'"; }
}
else
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

4
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...
4
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...
3
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...
2
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...
2
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,...
11
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...
10
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...
1
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...
2
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.