在表单中使用AjaxControlToolkit的日期选择器控件(比较2个日期选择器)

问题描述 投票:5回答:1

我正在使用普通的AjaxControlToolkit并在我的页面中使用2个datepicker。

第一个日期选择器采用的日期不是今天日期(今天或任何以前的日期)。在第二个文本框中,我可以选择第一个日期选择器中的日期到今天日期之间的日期。

我正在使用的脚本代码适用于JQuery日期选择器。但它不适用于普通的Ajax日期选择器。

这是代码如下:

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

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>

<!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>Date Picker</title>

<script type="text/C#" >

$(function () {
    $("#txtfrom").datepicker({
        onSelect: function (date) {
            $("#txtto").datepicker({
                minDate: date,
                maxDate: new Date()
            });
        },
        maxDate: 0
    });

}); 


</script>
</head>

<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<div>
<b>From</b>
<asp:TextBox ID="txtfrom" runat="server"></asp:TextBox>
<cc1:CalendarExtender ID="ceLoanTakenDate" runat="server" Format="dd/MM/yyyy"     PopupButtonID="txtfrom" TargetControlID="txtfrom">
    </cc1:CalendarExtender>
    &nbsp &nbsp
    <b>To</b>
    <asp:TextBox ID="txtto" runat="server"></asp:TextBox>
<cc1:CalendarExtender ID="CalendarExtender1" runat="server" Format="dd/MM/yyyy" PopupButtonID="txtto"  TargetControlID="txtto">
    </cc1:CalendarExtender>


</div>
</form>
</body>
</html>
asp.net ajaxcontroltoolkit
1个回答
0
投票

您需要处理第一个扩展器的客户端DateSelectionChanged事件并设置第二个扩展器的startDate属性:

<b>From</b>
<asp:TextBox ID="txtfrom" runat="server"></asp:TextBox>
<ajaxToolkit:CalendarExtender ID="ceLoanTakenDate" runat="server" Format="dd/MM/yyyy" 
    PopupButtonID="txtfrom" TargetControlID="txtfrom" 
    OnClientDateSelectionChanged="ceLoanTakenDate_dateSelectionChanged">
</ajaxToolkit:CalendarExtender>
&nbsp;&nbsp;
<b>To</b>
<asp:TextBox ID="txtto" runat="server"></asp:TextBox>
<ajaxToolkit:CalendarExtender ID="CalendarExtender1" runat="server" Format="dd/MM/yyyy" PopupButtonID="txtto"
    TargetControlID="txtto">
</ajaxToolkit:CalendarExtender>

<script type="text/javascript">
    function ceLoanTakenDate_dateSelectionChanged(sender, args) {
        $find("<%= CalendarExtender1.ClientID %>").set_startDate(sender.get_selectedDate());
    }
</script>
© www.soinside.com 2019 - 2024. All rights reserved.