Click here to Skip to main content
15,039,244 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
In my dotnet application i am having two calendar extender(ajax tool kit).
arrival date and departure date.
after i select arrival date , i do not want to allow to select departure date before the arrival date. how can i do that?


thanks
afsal
Posted
Comments
bhagirathimfs 21-Jun-12 1:59am
   
You are using datepicker ?
afsal.mp 21-Jun-12 2:06am
   
i am using calendar extender( from ajax toolkit)
afsal.mp 21-Jun-12 2:07am
   
<div class="txt_containner">
<div class="txt_name_box">Arrival Date</div>
<div class="txt_box"><asp:TextBox ID ="txt_arrival_date" runat ="server" CssClass="txt_box_colour" >
<asp:RequiredFieldValidator ID="rfv_arrival_date" runat="server" ControlToValidate="txt_arrival_date" ErrorMessage="*" ValidationGroup="add">
</div>
<asp:CalendarExtender ID="CalendarExtender3" Format="dd MMM yy" runat="server" TargetControlID="txt_arrival_date">

</div>
<div class="txt_containner">
<div class="txt_name_box">Departure Date</div>
<div class="txt_box"><asp:TextBox ID ="txt_dep_date" runat ="server" CssClass="txt_box_colour" >
<asp:RequiredFieldValidator ID="rfv_dep_date" runat="server" ControlToValidate="txt_dep_date" ErrorMessage="*" ValidationGroup="add">
</div>
<asp:CalendarExtender ID="CalendarExtender2" Format="dd MMM yy" runat="server" TargetControlID="txt_dep_date">

</div>

Rewrite tax of calender extenders following way & call CompareValidator to compare two dates in following ways

XML
<asp:TextBox runat="server" ID="MyTextBoxArrivalDate"></asp:TextBox>
<asp:Label ID="LabelArrival" runat="server" Text="(dd/MM/yyyy)"></asp:Label>
<ajax:CalendarExtender ID="MyTextBoxArrivalDate" TargetControlID="MyTextBoxArrivalDate"
      Format="dd/MM/yyyy" runat="server" />

<asp:TextBox runat="server" ID="MyTextBoxDepartureDate"></asp:TextBox>
<asp:Label ID="LabelDeparture" runat="server" Text="(dd/MM/yyyy)"></asp:Label>
<ajax:CalendarExtender ID="MyTextBoxDepartureDate" TargetControlID="MyTextBoxDepartureDate"
      Format="dd/MM/yyyy" runat="server" />

<br/>
 <asp:CompareValidator  ID="cmpEndDate" runat="server" ErrorMessage="Date range not valid."
      ControlToCompare="MyTextBoxArrivalDate" ControlToValidate="MyTextBoxDepartureDate" ValueToCompare="MyTextBoxArrivalDate"
      Operator="GreaterThanEqual" Type="Date" ValidationGroup="NameOfValidationGroup"></asp:CompareValidator>


Note set appropriate value of ValidationGroup property of CampareValidator
   
This may help you

JavaScript
$("#txtArrivalDate").datepicker({
                dateFormat: 'yy-mm-dd',
                numberOfMonths: 1,
                onSelect: function (selected) {
                    $("#txtDepartureDate").datepicker("option", "minDate", selected)
                }
            });

            $("#txtDepartureDate").datepicker({
                dateFormat: 'yy-mm-dd',
                numberOfMonths: 1,
                onSelect: function (selected) {
                    $("#txtArrivalDate").datepicker("option", "maxDate", selected)
                }
            });
   
Comments
afsal.mp 21-Jun-12 2:09am
   
<div class="txt_containner">
<div class="txt_name_box">Arrival Date</div>
<div class="txt_box"><asp:TextBox ID ="txt_arrival_date" runat ="server" CssClass="txt_box_colour" >
<asp:RequiredFieldValidator ID="rfv_arrival_date" runat="server" ControlToValidate="txt_arrival_date" ErrorMessage="*" ValidationGroup="add">
</div>
<asp:CalendarExtender ID="CalendarExtender3" Format="dd MMM yy" runat="server" TargetControlID="txt_arrival_date">

</div>
<div class="txt_containner">
<div class="txt_name_box">Departure Date</div>
<div class="txt_box"><asp:TextBox ID ="txt_dep_date" runat ="server" CssClass="txt_box_colour" >
<asp:RequiredFieldValidator ID="rfv_dep_date" runat="server" ControlToValidate="txt_dep_date" ErrorMessage="*" ValidationGroup="add">
</div>
<asp:CalendarExtender ID="CalendarExtender2" Format="dd MMM yy" runat="server" TargetControlID="txt_dep_date">

</div>

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