简体   繁体   中英

Disable future dates selection in Ajax Calendar

I have tried this code to disable future dates to be selected but it does not seem to be working.

public void Calendar1_DayRender(object o, DayRenderEventArgs e)
{
    if (e.Day.Date < DateTime.Today)
    {
        e.Day.IsSelectable = false;
    }
}
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server" />
    <link href="CSS.css" rel="stylesheet" type="text/css" />
    <script src="Extension.min.js" type="text/javascript"></script>

    <asp:TextBox ID="txtDate" runat="server" CssClass="disable_future_dates" />
    <asp:ImageButton runat="server" ID="imgPopup" ImageUrl="~/Calendar.png" />
    <cc1:CalendarExtender ID="CalendarExtender1" runat="server" TargetControlID="txtDate"
        PopupButtonID="imgPopup" />
    </form>
</body>
</html>

Disabling Future Dates

In order to disable future dates we need to follow 2 simple steps.

  1. Add CSS.css and Extension.min.js files just below the ScriptManager as shown in the HTML Markup above.

  2. Set the CssClass property to disable_future_dates for the TextBox control associated with the CalendarExtender for which you want to disable the future dates.

That's it you need to do and your AJAX CalendarExtender will now disable the future dates.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM