How to use comparevalidator to compare date in ASP.NET 3.5?

In designer,

<asp:CompareValidator ID=”cvReturnDate” runat=”server”

                            ControlToValidate=”txtReturnDate”

                            ErrorMessage=”Return date must be valid date.” Type=”Date”

                            ValidationGroup=”validateInquiry” >*</asp:CompareValidator>

In Code,

                    this.cvReturnDate.Operator = ValidationCompareOperator.GreaterThan;

                    this.cvReturnDate.ValueToCompare = DateTime.Now.ToShortDateString();

or you just want to check if it is a date, the use this code instead,

this.cvReturnDate.Operator = ValidationCompareOperator.DataTypeCheck;

Advertisements
This entry was posted in ASP.NET 3.5, ASP.NET 3.5 And C# 3.5, C# 3.5. Bookmark the permalink.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s