Click here to Skip to main content
15,867,568 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am having two textbox having ajax calendar for both. In this the Ajax calendar is set for selecting months not the dates that was successful. Now I don't want to select the previous months and future months and reflect in the textbox. I was given StartDate and EndDate in Page_Load event to restrict the user not to select the before the StartMonth and after the EndMonth.

For this I disabled past and future months but when selecting the disabled months then I am getting the selected value into the textbox which was not the expected one. For this type of scenario how to handle the months.

What I have tried:

<ajaxToolkit:CalendarExtender ID="calendarSource" ClientIDMode="Static" runat="server"
                TargetControlID="txtStartDate" Format="yyyy-MM" DefaultView="Months" OnClientShown="onCalendarShownSource"
                OnClientHidden="onCalendarHiddenSource" PopupButtonID="imgStart" />


function onCalendarHiddenSource() {
            var cal = $find("calendarSource");
            if (cal._monthsBody) {
                for (var i = 0; i < cal._monthsBody.rows.length; i++) {
                    var row = cal._monthsBody.rows[i];
                    for (var j = 0; j < row.cells.length; j++) {
                        $removeHandler(row.cells[j].firstChild, "click", callSource);
                    }
                }
            }
        }

        function onCalendarShownSource() {
            var cal = $find("calendarSource");
            cal._switchMode("months", true);
            if (cal._monthsBody) {
                for (var i = 0; i < cal._monthsBody.rows.length; i++) {
                    var row = cal._monthsBody.rows[i];
                    for (var j = 0; j < row.cells.length; j++) {
                        $addHandler(row.cells[j].firstChild, "click", callSource);
                    }
                }
            }
        }

        function callSource(eventElement) {
            var target = eventElement.target;
            switch (target.mode) {
                case "month":
                    var cal = $find("calendarSource");
                    cal._visibleDate = target.date;
                    cal.set_selectedDate(target.date);
                    cal._blur.post(true);
                    cal.raiseDateSelectionChanged();
                    break;
            }
        }
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900