How to disable future date in ajax calendarextender

8.8k views Asked by At

I have an user control in AJAX for the date calendar and I want to disable the future dates in the Calendar. I have tried to do it by using the Maximum Value property but that doesn't disables the control.

Any suggestions or help?

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="usrCtrlDatePicker.ascx.cs" Inherits="UserControls_usrCtrlDatePicker" %>
<table cellspacing="0" cellpadding="0" border="0" style="height:18px;">
    <tr>
        <td style="text-align:center; vertical-align:middle; height:16px">
            <asp:TextBox ID="txtDateEntry" runat="server" Width="75px" MaxLength="1" style="text-align:justify"/>
            <img alt="" id="btnShowCalendar" runat="server" src="../images/calendar.gif" style="margin-left:-4px; margin-bottom:-3px; height:17px; width:17px;" />
            <ajax:MaskedEditExtender ID="meeDateEntry" runat="server"
                TargetControlID="txtDateEntry"
                Mask="99/99/9999"
                MessageValidatorTip="false"
                CultureName="en-US"
                OnFocusCssClass="MaskedEditFocus"
                OnInvalidCssClass="MaskedEditError"
                MaskType="Date"
                ErrorTooltipEnabled="false"   />
            <ajax:MaskedEditValidator ID="mevDateEntry"  runat="server" ControlExtender="meeDateEntry" ControlToValidate="txtDateEntry" Display="Dynamic" EmptyValueBlurredText="*" EmptyValueMessage="Date is required" InvalidValueBlurredMessage="*" InvalidValueMessage="Date is invalid" IsValidEmpty="false" MaximumValueBlurredMessage="sjdfhsdfh" MaximumValueMessage="Maximum Value Exceeded." TooltipMessage="" ValidationExpression="(0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])[- /.](19|20)\d\d" ValidationGroup="" />
             <ajax:CalendarExtender ID="ceDateEntry" runat="server"
                Format="MM/dd/yyyy" 
                TargetControlID="txtDateEntry" 
                PopupButtonID="btnShowCalendar" />
        </td>
    </tr>
</table>
2

There are 2 answers

3
ashokd On

You can use OnClientDateSelectionChanged event. Refer this.

3
Tanzeel ur Rehman On

I want to disable the future dates in the Asp.net ajax calendar extender

By setting the EndDate property of calendar extender you can achieve this required functionality or by using css class. css class technique is given below in the second link

For reference please check the following links, In the second link it uses css class to disable future dates.

Disable Future and Past Date

Disable Future Dates in ASP.Net AJAX