I have 4 dropdown boxes (fromDay, fromMonth, ToDay and ToMonth)
I want to be able to test to make sure that the dates are valid and the the
From dates are < the To dates.
When I add the records to the database, I typically use something like:
FromMonth.SelectedValue & "/01/" & FromYear.SelectedValue
I also have other validators on the screen for emails and required fields.
How would I set up a validator to handle this situation?
I was looking at setting a Custom validator or a CompareValidator to handle
the fields. I would need to move the variables into a temporary variable
for testing (sting or label).
The problem is that it would need to fire after I set up the temporary
variables. All the other validators would fire on submit.
How would I set up this validator to fire after the others and after I have
set up the variables for it to Validate?
Thanks,
Tom 11 1316
tshad wrote: I have 4 dropdown boxes (fromDay, fromMonth, ToDay and ToMonth)
I want to be able to test to make sure that the dates are valid and the the From dates are < the To dates.
When I add the records to the database, I typically use something like:
FromMonth.SelectedValue & "/01/" & FromYear.SelectedValue
I also have other validators on the screen for emails and required fields.
How would I set up a validator to handle this situation?
I was looking at setting a Custom validator or a CompareValidator to handle the fields. I would need to move the variables into a temporary variable for testing (sting or label).
The problem is that it would need to fire after I set up the temporary variables. All the other validators would fire on submit.
How would I set up this validator to fire after the others and after I have set up the variables for it to Validate?
Thanks,
Tom
Mixing validators can be a real pain. This is the reason I ended up
moving to 100% CustomValidators. You still dont get much control on the
order they validate, but at least they will all validate at the same
time. If you need to control the order you may want to create your own
labels/etc and roll it all into one function that fires on IsPostBack()
--
Curt Christianson
site: http://www.darkfalz.com
blog: http://blog.darkfalz.com
"Curt_C [MVP]" <software_at_darkfalz.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl... tshad wrote: I have 4 dropdown boxes (fromDay, fromMonth, ToDay and ToMonth)
I want to be able to test to make sure that the dates are valid and the the From dates are < the To dates.
When I add the records to the database, I typically use something like:
FromMonth.SelectedValue & "/01/" & FromYear.SelectedValue
I also have other validators on the screen for emails and required fields.
How would I set up a validator to handle this situation?
I was looking at setting a Custom validator or a CompareValidator to handle the fields. I would need to move the variables into a temporary variable for testing (sting or label).
The problem is that it would need to fire after I set up the temporary variables. All the other validators would fire on submit.
How would I set up this validator to fire after the others and after I have set up the variables for it to Validate?
Thanks,
Tom Mixing validators can be a real pain. This is the reason I ended up moving to 100% CustomValidators. You still dont get much control on the order they validate, but at least they will all validate at the same time. If you need to control the order you may want to create your own labels/etc and roll it all into one function that fires on IsPostBack()
But how do I get the CustomValidator to fire after I have set up the
asp:Labels:
FromDate.Text = FromMonth.SelectedValue & "/01/" & FromYear.SelectedValue
ToDate.Text = ToMonth.SelectedValue & "/01/" & ToYear.SelectedValue
Validate it now
Also, what would be the best way to validate it? I am trying to make sure
the FromDate is before or equal to the ToDate
Thanks,
Tom -- Curt Christianson site: http://www.darkfalz.com blog: http://blog.darkfalz.com But how do I get the CustomValidator to fire after I have set up the asp:Labels:
The custom validator should fire on the postback automatically, if not
do a page.Validate() call and a page.IsValid() check to see if it passed.
--
Curt Christianson
site: http://www.darkfalz.com
blog: http://blog.darkfalz.com
Hi Tom,
I see this question pop up on the newsgroup from time to time so I gave it
a go.
The code below works but sometimes needs 2 button clicks to fire a valid
date combination to the server.
I'll track that issue if I have time or let me know if you solved it.
Some things I found out while coding :
- Validators can't reference hiddenfields for validation. I had to use textboxes
with a display:none to let the validators do its work
- The CampareValidator in Date mode doest support the time component (1/1/2000
is ok but 1/1/2000 17:18 is not)
The below code uses my local for dates which is d/m/y.
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
RegisterOnSubmitStatement("keyXYZ", "Combine();");
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<script language="javascript">
function Combine(){
document.getElementById("TextBox5").value = '1/' + document.getElementById("TextBox1").value
+ '/' + document.getElementById("TextBox2").value;
document.getElementById("TextBox6").value = '1/' + document.getElementById("TextBox3").value
+ '/' + document.getElementById("TextBox4").value;
}
</script>
<form id="form1" runat="server">
<div>
Month<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>Year<asp:TextBox
ID="TextBox2"
runat="server"></asp:TextBox> <asp:TextBox ID="TextBox5"
Style="display: none"
runat="server" ></asp:TextBox>
<br />
Month<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>Year
<asp:TextBox ID="TextBox4" runat="server"></asp:TextBox>
<asp:TextBox ID="TextBox6" Style="display: none" runat="server"></asp:TextBox>
<br />
<asp:Button ID="Button1" runat="server" Text="Button" />
<asp:CompareValidator ID="CompareValidator1" runat="server" ControlToCompare="TextBox6"
ControlToValidate="TextBox5" ErrorMessage="CompareValidator"
Operator="LessThan"
Type="Date"></asp:CompareValidator></div>
</form>
</body>
</html>
Let me know if it helped you or not...
Cheers,
Tom Peste
"tshad" <ts**********@ftsolutions.com> wrote in
news:#q**************@tk2msftngp13.phx.gbl: I have 4 dropdown boxes (fromDay, fromMonth, ToDay and ToMonth)
I want to be able to test to make sure that the dates are valid and the the From dates are < the To dates.
You can use IsDate to test if the Date is valid.
Once you know it is a date, you can cast the string to a date and do a > or
< comparison.
--
Lucas Tam (RE********@rogers.com)
Please delete "REMOVE" from the e-mail address when replying. http://members.ebay.com/aboutme/coolspot18/
"Curt_C [MVP]" <software_at_darkfalz.com> wrote in message
news:es**************@TK2MSFTNGP14.phx.gbl... But how do I get the CustomValidator to fire after I have set up the asp:Labels:
The custom validator should fire on the postback automatically, if not do a page.Validate() call and a page.IsValid() check to see if it passed.
But I don't want it to fire on PostBack automatically because I want to set
up the Date Labels first.
Would I have to set the Button CausesValidation to false first, Set the
Labels and then do Valiate()?
Tom
-- Curt Christianson site: http://www.darkfalz.com blog: http://blog.darkfalz.com
"tom pester" <To********************@pandora.be> wrote in message
news:a1**************************@news.microsoft.c om... Hi Tom,
I see this question pop up on the newsgroup from time to time so I gave it a go. The code below works but sometimes needs 2 button clicks to fire a valid date combination to the server. I'll track that issue if I have time or let me know if you solved it.
It doesn't help if I have to do 2 button clicks to make it work.
Are you doing it in Javascript to get it done before the Validation?
Tom Some things I found out while coding : - Validators can't reference hiddenfields for validation. I had to use textboxes with a display:none to let the validators do its work - The CampareValidator in Date mode doest support the time component (1/1/2000 is ok but 1/1/2000 17:18 is not)
The below code uses my local for dates which is d/m/y. <%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<script runat="server">
protected void Page_Load(object sender, EventArgs e) { RegisterOnSubmitStatement("keyXYZ", "Combine();"); }
</script>
<html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>Untitled Page</title> </head> <body>
<script language="javascript"> function Combine(){ document.getElementById("TextBox5").value = '1/' + document.getElementById("TextBox1").value + '/' + document.getElementById("TextBox2").value; document.getElementById("TextBox6").value = '1/' + document.getElementById("TextBox3").value + '/' + document.getElementById("TextBox4").value; } </script>
<form id="form1" runat="server"> <div> Month<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>Year<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox> <asp:TextBox ID="TextBox5" Style="display: none" runat="server" ></asp:TextBox> <br /> Month<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>Year <asp:TextBox ID="TextBox4" runat="server"></asp:TextBox> <asp:TextBox ID="TextBox6" Style="display: none" runat="server"></asp:TextBox> <br /> <asp:Button ID="Button1" runat="server" Text="Button" /> <asp:CompareValidator ID="CompareValidator1" runat="server" ControlToCompare="TextBox6" ControlToValidate="TextBox5" ErrorMessage="CompareValidator" Operator="LessThan" Type="Date"></asp:CompareValidator></div> </form> </body> </html>
Let me know if it helped you or not...
Cheers, Tom Pester
Hi Tom,
Its a client side javascript soltion ( and it will also validate on the server
afterwards ).
Check out RegisterOnSubmitStatement. Can you see whats going on?
Cheers,
Tom Pester It doesn't help if I have to do 2 button clicks to make it work.
Are you doing it in Javascript to get it done before the Validation?
Tom
tshad wrote: "Curt_C [MVP]" <software_at_darkfalz.com> wrote in message news:es**************@TK2MSFTNGP14.phx.gbl...
But how do I get the CustomValidator to fire after I have set up the asp:Labels:
The custom validator should fire on the postback automatically, if not do a page.Validate() call and a page.IsValid() check to see if it passed.
But I don't want it to fire on PostBack automatically because I want to set up the Date Labels first.
Would I have to set the Button CausesValidation to false first, Set the Labels and then do Valiate()?
Tom
-- Curt Christianson site: http://www.darkfalz.com blog: http://blog.darkfalz.com
Why would you need to set the labels FIRST? just fill em in the
postback. They are already clicking the button. Fill em with clientsdie
code otherwise.
--
Curt Christianson
site: http://www.darkfalz.com
blog: http://blog.darkfalz.com
"Curt_C [MVP]" <software_at_darkfalz.com> wrote in message
news:eF**************@TK2MSFTNGP10.phx.gbl... tshad wrote: "Curt_C [MVP]" <software_at_darkfalz.com> wrote in message news:es**************@TK2MSFTNGP14.phx.gbl...
But how do I get the CustomValidator to fire after I have set up the asp:Labels: The custom validator should fire on the postback automatically, if not
doa page.Validate() call and a page.IsValid() check to see if it passed.
But I don't want it to fire on PostBack automatically because I want to
set up the Date Labels first.
Would I have to set the Button CausesValidation to false first, Set the Labels and then do Valiate()?
Tom
-- Curt Christianson site: http://www.darkfalz.com blog: http://blog.darkfalz.com
Why would you need to set the labels FIRST? just fill em in the postback. They are already clicking the button. Fill em with clientsdie code otherwise.
Does it handle the IsPostback code before it Validates()?
If that is true, you're right - I can do it there.
Tom
-- Curt Christianson site: http://www.darkfalz.com blog: http://blog.darkfalz.com
Use a custom validator(s). You can make one for each date element (mm,
dd, yy) and/or one for the entire date. Set the control to validate
for the entire date on the the last item. The indivduals will fire as
you change each control. So if you select/add 31 in the dd field and
the mm is set to two, then the dd field will fire. The validators fire
in the order they are added to the page. (Have not validated this but
that is how it appears to work.) The final control validates the
entire date. You will need to reference all of the date controls in
your JavaScript. I have found it easier to add an array or custom
variables in script during postback to then reference in my validation
script functions. That way you have the unique id of the control as it
is rendered. Good luck and good coding. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Steve |
last post by:
I am currently trying to validate data in an access database. I need
to verify that columns containing date information are in the format
ddmmyyyy and columns containg time information are in the...
|
by: John Livermore |
last post by:
In C# what is the best way to validate that a particular string
entered by a user will actually convert to a date w/o using a try
catch block or writing code to explicitly parse the string?
Here...
|
by: Jorge EA |
last post by:
Hi there,
According to the following article, a textbox for a date entry field can be
validated with a CompareValidator:
...
|
by: John |
last post by:
Hi
I have a web control text box on my webform which I want to use for entering
dates. Is there a way to validate this text box field for valid dates? May
be using a validators such as regular...
|
by: Patrick.O.Ige |
last post by:
I'm using this CompareValidator to validate dates but my default its
mm/dd/yyyy
<asp:CompareValidator ControlToValidate="DOB" Display="Dynamic"
Text="Invalid birth date!" Operator="DataTypeCheck"...
|
by: =?Utf-8?B?Ym9iYnk=?= |
last post by:
I have a textBox Where I type date. I want to validate it. Im using
customValidate controls. I have this function in my code behind page
void DatesValidate(object source,...
|
by: Just Me |
last post by:
Hi people.
I am attempting to determine how best to prevent a users date entry in an
update action from causing a format exception. The dates are UK, but the
user may try to put in a 'US'...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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,...
|
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,...
|
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: 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...
| |