2

嗨,我的所有设计Rad Panel bar如下

 <telerik:RadPanelBar runat="server" ID="rdpnlPersonal" ExpandMode="FullExpandedItem"
                Skin="Vista" EnableEmbeddedSkins="false" Width="880px">
                <Items>
                    <telerik:RadPanelItem Expanded="true" Text="Employee Personal Information" runat="server"
                        Selected="true">
                        <Items>
                            <telerik:RadPanelItem Value="AccountInformation" runat="server">
                                <ItemTemplate>
                                    <label>
                                        Demop
                                    </label>
                                    <telerik:RadDatePicker ID="RadDatePicker1" Width="200px" runat="server" MinDate="1900-01-01"
                                        TabIndex="5">
                                        <Calendar ID="Calendar1" RangeMinDate="1900-01-01" runat="server">
                                        </Calendar>
                                    </telerik:RadDatePicker>
                                    <telerik:RadDatePicker ID="radDtHiredate" Width="200px" runat="server" MinDate="1900-01-01"
                                        TabIndex="5">
                                        <Calendar ID="calHire" RangeMinDate="1900-01-01" runat="server">
                                        </Calendar>
                                    </telerik:RadDatePicker>
                                    <asp:CustomValidator ID="CustomValidator1" runat="server" ClientValidationFunction="validatehiredate"
                                        SetFocusOnError="true" ControlToValidate="radDtHiredate" ValidationGroup="accountValidation"
                                        Display="Dynamic">Can not Hire Guy less than 18 yrs</asp:CustomValidator>
                                    <br />
                                    <telerik:RadButton ID="rdbtnwhAnother" Text="Add WithHolding" runat="server" ButtonType="LinkButton"
                                        ValidationGroup="accountValidation" OnClick="rdbtnwhAnother_Click">
                                    </telerik:RadButton>
                                </ItemTemplate>
                            </telerik:RadPanelItem>
                        </Items>
                    </telerik:RadPanelItem>
                </Items>
            </telerik:RadPanelBar>

这里我需要的是,如果所选日期小于18 years我希望在Custom validator. 为此,我编写了以下脚本,但我无法实现所需的..

我的脚本如下

 <script type="text/javascript" language="javascript">
    function monthDiff(d1, d2) {
        alert("Mon");
        var months;
        var date1 = new Date(d1);
        var date2 = new Date(d2);
        return (date1 - date2) / (1000 * 60 * 60 * 24);
        return months;
    }


    //function getLeapYear

    function difference(d1, d2) {
        var hiredate, dob; var diff = 18 * 12;
        hiredate = document.getElementById(d1).get_selectedDate();
        dob = document.getElementById(d2).get_selectedDate();
        var Age = monthDiff(hiredate, dob);

        var compareVal = 365 * 18; //getCompareVal(hiredate,dob);

        if (Age >= compareVal) {
            return true;
            //true
        } else {
            return false; //false
        }
    }
    function validatehiredate(value, arg) {
        var datePicker = $find('<%# rdpnlPersonal.FindItemByText("Employee Personal Information").FindControl("RadDatePicker1").ClientID %>');
        var datePicker1 = $find('<%# rdpnlPersonal.FindItemByText("Employee Personal Information").FindControl("radDtDOB").ClientID %>');
        arg.IsValid = (difference(datePicker, datePicker1));
    }
</script>

有人能帮助我吗

4

1 回答 1

1

毕竟我通过在radcodeblock中编写脚本解决了如下问题

<telerik:RadCodeBlock runat="server" ID="radcb">
        <script type="text/javascript" language="javascript">
            function monthDiff(d1, d2) {
                var months;
                var date1 = new Date(d1);
                var date2 = new Date(d2);
                return (date1 - date2) / (1000 * 60 * 60 * 24);
                return months;
            }

            //function getLeapYear

            function difference(d1, d2) {
                var diff = 18 * 12;
                var Age = monthDiff(d1, d2);

                var compareVal = 365 * 18; //getCompareVal(hiredate,dob);

                if (Age >= compareVal) {
                    return true;
                    //true
                } else {
                    return false; //false
                }
            }
            function validatehiredate(value, arg) {
                var datePicker = $find('<%= rdpnlPersonal.FindItemByValue("AccountInformation").FindControl("radDtHiredate").ClientID %>');
                var datePicker1 = $find('<%= rdpnlPersonal.FindItemByValue("AccountInformation").FindControl("radDtDOB").ClientID %>');

                var date = datePicker.get_selectedDate();
                var date1 = datePicker1.get_selectedDate();
                arg.IsValid = (difference(date, date1));
            }
        </script>
    </telerik:RadCodeBlock>
于 2012-06-26T11:57:52.350 回答