在日历中设置最长日期

时间:2013-12-26 13:04:13

标签: asp.net ajax visual-studio-2010 ajaxcontroltoolkit

我有两个日历来设置日期范围。第一个日历是从日期开始的,第二个日历是从日期开始的。我希望第二个日历最大选择日期是从日历1中选择的日期开始的三个月。如何在第二个日历中设置最大日期。

<tr>
<tr>
    <td style="width: 66px">
        <asp:Label ID="Label13" runat="server" SkinID="Title3" Text="Starting Date"></asp:Label>
    </td>
    <td>
        <table align="left" cellpadding="0" cellspacing="0" style="width: 100%;">
            <tr>
                <td style="width: 289px">
                    <asp:TextBox ID="txtStartingDate" runat="server" CssClass="textbox" TextChanged="txtFromDateChanged"></asp:TextBox>
                    <img id="Img1" alt="Calender" src="../../Images/Calendar_Icon.png" visible="false" />
                    <ajaxtoolkit:calendarextender id="CalendarExtender1" runat="server" enabled="True"
                        format="dd/MM/yyyy" popupbuttonid="sDateBtn" targetcontrolid="txtStartingDate">
                                                                                                    </ajaxtoolkit:calendarextender>
                    <ajaxtoolkit:maskededitextender id="MaskedEditExtender1" runat="server" cultureampmplaceholder=""
                        culturecurrencysymbolplaceholder="" culturedateformat="" culturedateplaceholder=""
                        culturedecimalplaceholder="" culturethousandsplaceholder="" culturetimeplaceholder=""
                        enabled="True" mask="99/99/9999" masktype="Date" targetcontrolid="txtStartingDate">
                                                                                                    </ajaxtoolkit:maskededitextender>
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="txtStartingDate"
                        ValidationGroup="ValidationGroup"></asp:RequiredFieldValidator>
                </td>
                <td style="width: 149px">
                    &nbsp;
                </td>
                <td valign="top">
                    &nbsp;
                </td>
            </tr>
        </table>
    </td>
</tr>
<tr>
    <td style="width: 66px">
        <asp:Label ID="Label14" runat="server" SkinID="Title3" Text="Ending Date"></asp:Label>
    </td>
    <td>
        <table align="left" cellpadding="0" cellspacing="0" style="width: 100%;">
            <tr>
                <td style="width: 289px">
                    <asp:TextBox ID="txtEndingDate" runat="server" CssClass="textbox"></asp:TextBox>
                    <img id="eDateBtn" alt="Calender" src="../../Images/Calendar_Icon.png" visible="false" />
                    <ajaxtoolkit:calendarextender id="CalendarExtender2" runat="server" enabled="true"
                        format="dd/MM/yyyy" popupbuttonid="eDateBtn" targetcontrolid="txtEndingDate">
                                                                                                    </ajaxtoolkit:calendarextender>
                    <ajaxtoolkit:maskededitextender id="MaskedEditExtender2" runat="server" cultureampmplaceholder=""
                        culturecurrencysymbolplaceholder="" culturedateformat="" culturedateplaceholder=""
                        culturedecimalplaceholder="" culturethousandsplaceholder="" culturetimeplaceholder=""
                        enabled="True" mask="99/99/9999" masktype="Date" targetcontrolid="txtEndingDate">
                                                                                                    </ajaxtoolkit:maskededitextender>
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate="txtEndingDate"
                        ValidationGroup="ValidationGroup"></asp:RequiredFieldValidator>
                    <asp:RangeValidator ID="RangeValidator1" runat="server" ControlToValidate="CalendarExtender2"
                        ErrorMessage="RangeValidator" Type="Date" Visible="false">
                    </asp:RangeValidator>
                </td>
                <td valign="top">
                    &nbsp;
                </td>
                <td valign="top">
                    &nbsp;
                </td>
            </tr>
        </table>
    </td>
</tr>
<tr>

////来自日期文本更改事件的文本,但在调试

时不会遇到此问题
public void txtFromDateChanged(object sender, EventArgs e)
        {

            DateTime selectedFromDate = DateTime.Parse(txtStartingDate.Text.ToString());
            DateTime maxDate = selectedFromDate.AddMonths(3);
            RangeValidator1.MaximumValue = maxDate.ToString();


        }

1 个答案:

答案 0 :(得分:0)

您始终可以使用RangeValidator的MaximumValue属性来执行此操作。 Tiy可以首先在Page_Load方法中设置RangeValidator1.MaximumValue的值。有关该酒店的更多详情,请阅读http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.rangevalidator.maximumvalue(v=vs.110).aspx