The following is the code I'm using to select a date in asp.net
I'm using a text box to display the date and image to show the calender icon, and Ajax calender extender to select the date in the format dd-mmm-yyyy.
<asp:TextBox ID="txtReqCompDate" runat="server"
ToolTip="Select Analysis Required Date" CssClass="formtext"
CausesValidation="True">
</asp:TextBox>
<asp:ImageButton ID="ibReqCompletionDate" runat="server"
ImageUrl="~/Images/Calendar.png" ImageAlign="AbsBottom" Height="15px" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server"
ControlToValidate="txtReqCompDate" Display="Dynamic" Text="Required"
ErrorMessage="Analysis Required Date" ValidationGroup="valProjForm"
SetFocusOnError="True" Font-Size="Smaller">
</asp:RequiredFieldValidator>
<asp:CompareValidator runat="server" ID="cmp1"
ErrorMessage="The date must be greater than todays date"
ControlToValidate="txtReqCompDate" Type="Date" Operator="GreaterThan" />
<cc1:CalendarExtender ID="CalendarExtender1" runat="server"
PopupButtonID="ibReqCompletionDate"
TargetControlID="txtReqCompDate" Format="dd-MMM-yyyy" Enabled="True">
</cc1:CalendarExtender>
Even If I use this line in page load there is no use.
cmp1.ValueToCompare = DateTime.Now.ToShortDateString();
Please suggest me a way to display a message right away when some one selects a date less than today's date using comparevalidator.
I need a similar functionality in several pages of my website. And also in the same page to select a date greater than txtReqCompDate.
Or please suggest me a way to disable the previous dates in ajax calenderextender and show the date ahead of the current date in Ajax extender without affecting my current code functionality as I'm coding in .net 2.0.
My Main issue here, it shows validation, if date is less than today's date and even when the date is greater than current date. Shows error message always whatever validator I use, compare or range
Instead of Compare validator, use range validator
You can modify it according to your requirement.