Date Compare Validator Control ASP.NET

Posted by Sahanr on ASP.net Weblogs See other posts from ASP.net Weblogs or by Sahanr
Published on Tue, 01 Feb 2011 22:20:00 GMT Indexed on 2011/02/01 23:26 UTC
Read the original article Hit count: 337

Filed under:
|

Compare two input dates to avoid invalid dates. In this example I have created two textboxes and namded as "TextBoxSeminarDate" and "TextBoxBookingDeadline". Booking deadline date must be before date to the Seminar date. Therefore I used Operator as "LesThanEqual".

I have validated "TextBoxBookingDeadline" value comparing with the "TextBoxSeminarDate" value as follow.

 

<asp:CompareValidator ID="CompareValidatorBookingDeadline" runat="server"

ControlToCompare="TextBoxSeminarDate"

ControlToValidate="TextBoxBookingDeadline" Display="Dynamic"

ErrorMessage="Please check the seminar date and select appropriate date for booking deadline"

Operator="LessThanEqual"

Type="Date" 

ValueToCompare="<%= TextBoxSeminarDate.Text.ToShortString() %>">*</asp:CompareValidator>

The important thing is "ValueToCompare" property of the compare validator. Here I have assined it to the value of the TextboxSeminarDate and then compered it with the booking deadline date.

 

© ASP.net Weblogs or respective owner

Related posts about ASP.NET

Related posts about c#