Home All Groups Group Topic Archive Search About

Complex CompareValidator Validations

Author
29 Jun 2005 4:18 PM
John Walker
Hi,
I have a datagrid with two ASP:TextBox TemplateColumns in which the user
will enter MM/DD/YYYY dates.  In one column, the date is not allowed to be
more than 7 days into the future; and in the other column, the date must be
less than or equal to today's date.  We would like this to be client side
validation.  Is it possible to handle these types of comparisons with
ASP:CompareValidator?  Or any other validator?

Thanks,
John

Author
29 Jun 2005 6:48 PM
Peter Blum
Yes, the CompareValidator with Type=Date works.
To set 7 days in the future:
CompareValidator1.ValueToCompare =
DateTime.Today.AddDays(7).ToShortDateString()
To set today:
CompareValidator2.ValueToCompare = DateTime.Today.ToShortDateString()

Additionally, add a CompareValidator to confirm that the text is actually a
valid date format so an entry like 99/99/9999 is considered invalid. The
ValueToCompare feature only works against valid dates so the second
validator is necessary.
CompareValidator with Type=Date and Operator=DataTypeCheck.

Even though this will provide client-side validation, you should ALWAYS
setup server side validation because the validators only provide client-side
validation on IE and IE/Mac and javascript can be turned off. (My
Professional Validation And More has validators that support many more
browsers.)

Its very easy to get server side validation. In the Click post back event
method, test Page.IsValid is true before saving.

--- Peter Blum
www.PeterBlum.com
Email: PLB***@PeterBlum.com
Creator of "Professional Validation And More" at
http://www.peterblum.com/vam/home.aspx

Show quoteHide quote
"John Walker" <JohnWal***@discussions.microsoft.com> wrote in message
news:D771D106-990D-42B4-BBC2-B73E12C33C12@microsoft.com...
> Hi,
> I have a datagrid with two ASP:TextBox TemplateColumns in which the user
> will enter MM/DD/YYYY dates.  In one column, the date is not allowed to be
> more than 7 days into the future; and in the other column, the date must
> be
> less than or equal to today's date.  We would like this to be client side
> validation.  Is it possible to handle these types of comparisons with
> ASP:CompareValidator?  Or any other validator?
>
> Thanks,
> John
Author
5 Jul 2005 7:05 PM
John Walker
Peter,

This works great!  Thanks!

John

Show quoteHide quote
"Peter Blum" wrote:

> Yes, the CompareValidator with Type=Date works.
> To set 7 days in the future:
> CompareValidator1.ValueToCompare =
> DateTime.Today.AddDays(7).ToShortDateString()
> To set today:
> CompareValidator2.ValueToCompare = DateTime.Today.ToShortDateString()
>
> Additionally, add a CompareValidator to confirm that the text is actually a
> valid date format so an entry like 99/99/9999 is considered invalid. The
> ValueToCompare feature only works against valid dates so the second
> validator is necessary.
> CompareValidator with Type=Date and Operator=DataTypeCheck.
>
> Even though this will provide client-side validation, you should ALWAYS
> setup server side validation because the validators only provide client-side
> validation on IE and IE/Mac and javascript can be turned off. (My
> Professional Validation And More has validators that support many more
> browsers.)
>
> Its very easy to get server side validation. In the Click post back event
> method, test Page.IsValid is true before saving.
>
> --- Peter Blum
> www.PeterBlum.com
> Email: PLB***@PeterBlum.com
> Creator of "Professional Validation And More" at
> http://www.peterblum.com/vam/home.aspx
>
> "John Walker" <JohnWal***@discussions.microsoft.com> wrote in message
> news:D771D106-990D-42B4-BBC2-B73E12C33C12@microsoft.com...
> > Hi,
> > I have a datagrid with two ASP:TextBox TemplateColumns in which the user
> > will enter MM/DD/YYYY dates.  In one column, the date is not allowed to be
> > more than 7 days into the future; and in the other column, the date must
> > be
> > less than or equal to today's date.  We would like this to be client side
> > validation.  Is it possible to handle these types of comparisons with
> > ASP:CompareValidator?  Or any other validator?
> >
> > Thanks,
> > John
>
>
>