locked
CalendarExtender change month RRS feed

  • Question

  • User1510859543 posted

    I have 2 date textbox controls (see below) using ACT. When I click on the textbox I get the calendar for the current month.  If I enter a date for a different month in the first textbox (txtTimeOffDate) I want the 2nd textbox (txtTimeOffDateTo) to popup the same month calendar instead of the current month.

                        <td><asp:TextBox ID="txtTimeOffDate" runat="server" Width="72" ClientIDMode="Static" onchange="setdateto(this);" />
                            <cc1:CalendarExtender ID="CalendarExtender3" runat="server" TargetControlID="txtTimeOffDate">
                            </cc1:CalendarExtender>
                            <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" 
                                ErrorMessage="Time off Date is required." Display="Dynamic" 
                                ControlToValidate="txtTimeOffDate">
                            </asp:RequiredFieldValidator>
                        </td>
                        <td><asp:TextBox ID="txtTimeOffDateTo" runat="server" Width="72" ClientIDMode="Static" />
                            <cc1:CalendarExtender ID="CalendarExtender4" runat="server" TargetControlID="txtTimeOffDateTo">
                            </cc1:CalendarExtender>
                        </td>
    

    Monday, August 10, 2020 6:49 PM

Answers

  • User-1330468790 posted

    Hi dlchase,

      

    You could set the "_visibleDate" for the second calendar so that it will automatically show the month dates including the visible date.

      

    More details, you could refer to below codes:

    <body>
        <script>
            function ApplyStartMonth(sender, args) {
                var calendarStart = $find('CalendarExtender3');
               
                sender.set_visibleDate(calendarStart._selectedDate);
               
                // the following is not needed here but good to know that they exist
                //sender.set_todaysDate(calendarStart._selectedDate);
                //sender.set_selectedDate(calendarStart._selectedDate);
            }
        </script>
        <form id="form1" runat="server">
            <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
    
            <div>
                <asp:TextBox ID="txtTimeOffDate" runat="server" Width="72" ClientIDMode="Static" />
    
                <ajaxToolkit:CalendarExtender ID="CalendarExtender3" runat="server" TargetControlID="txtTimeOffDate" ></ajaxToolkit:CalendarExtender>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
                    ErrorMessage="Time off Date is required." Display="Dynamic"
                    ControlToValidate="txtTimeOffDate">
                </asp:RequiredFieldValidator>
    
                <asp:TextBox ID="txtTimeOffDateTo" runat="server" Width="72" ClientIDMode="Static" />
                <ajaxToolkit:CalendarExtender ID="CalendarExtender4" runat="server" OnClientShown="ApplyStartMonth" TargetControlID="txtTimeOffDateTo"></ajaxToolkit:CalendarExtender>
            </div>
        </form>

    Demo:

     

    I referred to this post on SO: selecting particular month as default in calendar extender

     

    Best regards,

    Sean

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, August 11, 2020 3:40 AM