无法从Javascript中检索RadDatePicker对象

时间:2015-02-16 12:24:12

标签: javascript jquery asp.net telerik raddatepicker

我正在把头发拉过来,我无法使RadDatePicker的客户端API工作。该对象没有任何功能或没有属性。我想要简单只是想在javascript上创建一个RadDatePicker的对象。请检查 ClearControl 函数。想要在找到datepicker控件对象时使用set_selectedDate方法。像:

 var today = new Date();
 var dateAcc = $find("<%=dtpDODate.ClientID %>");
 dateAcc.set_selectedDate(today);

你能帮我在空白的aspx页面上找到这段代码的错误吗?

   <script type="text/javascript" language="javascript">
               function ClearControl(DivID) {
    try {
        var elements = null;
        if (DivID == null) {
            var oForm = document.forms['frmSiteMain'];
            if (!oForm) {
                oForm = document.form1;
            }
            elements = oForm.elements;
        }
        else {
            elements = document.getElementById(DivID).getElementsByTagName("input");
        }

        //  oForm.reset();
        for (i = 0; i < elements.length; i++) {
            if (elements[i].type != null) {
                field_type = elements[i].type.toLowerCase();

                if (field_type) {               

                        if ((elements[i].id.toString().search("body_") == 0 || elements[i].id.toString().search("ctl00_body_") == 0) && elements[i].id.toString().indexOf("_dtp") > 0) {
                               var today = new Date();
                            var control = $find(elements[i].id.toString());
                            control.set_selectedDate(today);                           
                            break;                         
                        }                  
                }
            }
        }

    }
    catch (e) {
        alert(e.message + " Type:" + field_type);
    }
}
</script>




    <div class="p_div" id="divDODate" runat="server">
        <div class="m1">
            <asp:Label ID="lblDODate" runat="server" Text="Date"></asp:Label>
            <telerik:RadDatePicker ID="dtpDODate" runat="server" MapColumnName="strDODate">
                <DateInput ID="DateInput1" DateFormat="MM/dd/yyyy" runat="server">
                </DateInput>

            </telerik:RadDatePicker>
        </div>
    </div>

感谢您的协助,

1 个答案:

答案 0 :(得分:0)

问题是具体的,错误的对象创建语法,请检查以下语法

 else if ((elements[i].id.toString().search("body_") == 0 || elements[i].id.toString().search("ctl00_body_") == 0) && elements[i].id.toString().indexOf("_dtp") > 0) {

                            var today = new Date();//get date
                            var control = $find(elements[i].id.toString());//create object of date picker control
                            control.set_selectedDate(today);//fill picker with date.
                            break;
                        }