[RESOLVED]Disable future date in Ajax CalendarExtender

Dear all,

i am using Ajax Control toolkit version 4.1. and i need to restrict user from entering future date. also in my web app user can enter date manul in textbox associated with Ajax Calendar extender control. any demo any suggestion. i need it urgently.

thanks.

Calender1.EndDate =DateTime.Now.Date; // here you enter your future date

Or you can use this for furture end date limit

Calender1.EndDate = DateTime.Now.AddDays(90);;

Sorry dear EndDate  property is not available to me. i am using ‘CalendarExtender’ from Ajax toolkit

hey search this property on internet its work fine 

yourAjaxCalenderID.EndDate =DateTime.Now.Date

Download the demo program from given link

https://skydrive.live.com/?lc=24841#cid=2F22272220E37707&id=2F22272220E37707%21103

Program name is =CalenerDateLimit

Shoail, 

thanks for your demo. its good but when i plug it into my app it does not work and also i cannot restrict date if user enter date manally in textbox. might be because of difference in minor version of Ajax toolkit that i am using

Hi,

Please refer to the code as follow:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Calendar_limit.aspx.cs" Inherits="test7" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<!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>

    <script type="text/javascript">
                function checkDate(sender, args) {
            if (sender._selectedDate < new Date()) {
                alert("You cannot select a day earlier than today!");
                sender._selectedDate = new Date();
                // set the date back to the current date
                sender._textbox.set_Value(sender._selectedDate.format(sender._format))
                        }

        }
    </script>

</head>
<body>
    <form id="form1" runat="server">
    <asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
    </asp:ToolkitScriptManager>
    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
    <asp:Button ID="Button1" runat="server" Text="Date"/>
    <asp:CalendarExtender ID="CalendarExtender1" BehaviorID="CalendarExtender1" runat="server" TargetControlID="TextBox1" PopupButtonID="Button1" OnClientDateSelectionChanged="checkDate">
    </asp:CalendarExtender>
    <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
    <asp:Button ID="Button2" runat="server" Text="test"/>
    <asp:CalendarExtender ID="CalendarExtender2" BehaviorID="CalendarExtender2" Format="dd/M/yy" runat="server" TargetControlID="TextBox2" PopupButtonID="Button2">
    </asp:CalendarExtender>
    </form>
</body>
</html>

Try this

<asp:CalendarID="Calendar1"runat="server"OnDayRender="Calendar1_DayRender"></asp:Calendar>

Protected
void
Calendar1_DayRender(object sender,DayRenderEventArgs
e
){
if(e.Day.Date>
DateTime.Today){ e.Day.IsSelectable=
false;}
}

You can follow this link to achieve it:
http://vincexu.blogspot.com/2008/11/how-to-disable-dates-which-are-less.html

Hi

refer this link it’s have a good example that may help you

http://www.aspsnippets.com/Articles/AJAX-CalendarExtender-Disable-Future-Date-Selection.aspx

nice then you have to use Compare Validator Expression with my provide demo

<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>

<asp:CompareValidator ID="CompareValidator1" runat="server" ControlToValidate="TextBox1"

ErrorMessage="CompareValidator" Operator="GreaterThanEqual" Type="Date"></asp:CompareValidator>



And Try to put this on page_load eventprotected void Page_Load(object sender, EventArgs e)
{

CompareValidator1.ValueToCompare = DateTime.Now.ToShortDateString();

}

Leave a Reply