J
James P.
Hello there,
In my asp.net page using VB, I have a date text field in mm/dd/yyyy
format. When a date is entered, I'd like to validate it to make sure
the date is greater than or equal to the current date. If not, I'd
like to display the error message to ValidationSummary.
It seems to make sense to me to use CompareValidator but the problem
is put the current date into CompareValidator. So, I created a hidden
text field in my aspx. In my VB code behind, I load current date to
that text field. Then, I created a CompareValidator to compare this
current date to the text field containing date entered by the user.
In my Page_Load, I have Page.Validate to activate the validation.
When I run it, the first round through, the validationSummary worked
and displayed the warning message I wanted (that date entered can't be
less than current date). However, it did not work after that. I
think the problem is server validation did not work properly.
My alternative way is to use client validation using CustomValidator.
Pass in two date fields: current date and entered date and compare.
Unfortunately, I don't know well neither javaScrip nor any other
script languages to do it. The problem I am having with this approach
is getting current date in the mm/dd/yyyy format so I can compare to
what the user enters in that format. Date() function is javascrip
returns a different format. And I think Now() returns both date and
time.
Any suggestions are greatly appreciated. Thank you in advance,
James
In my asp.net page using VB, I have a date text field in mm/dd/yyyy
format. When a date is entered, I'd like to validate it to make sure
the date is greater than or equal to the current date. If not, I'd
like to display the error message to ValidationSummary.
It seems to make sense to me to use CompareValidator but the problem
is put the current date into CompareValidator. So, I created a hidden
text field in my aspx. In my VB code behind, I load current date to
that text field. Then, I created a CompareValidator to compare this
current date to the text field containing date entered by the user.
In my Page_Load, I have Page.Validate to activate the validation.
When I run it, the first round through, the validationSummary worked
and displayed the warning message I wanted (that date entered can't be
less than current date). However, it did not work after that. I
think the problem is server validation did not work properly.
My alternative way is to use client validation using CustomValidator.
Pass in two date fields: current date and entered date and compare.
Unfortunately, I don't know well neither javaScrip nor any other
script languages to do it. The problem I am having with this approach
is getting current date in the mm/dd/yyyy format so I can compare to
what the user enters in that format. Date() function is javascrip
returns a different format. And I think Now() returns both date and
time.
Any suggestions are greatly appreciated. Thank you in advance,
James