0

localhost:3659/advancesearch.aspx 中第 289 行第 13 列的未处理异常

0x800a01a8 - Microsoft JScript 运行时错误:需要对象

我正在调用正确的函数,但错误仍然存​​在。

HTML 代码:

<script type="text/javascript" language="javascript">
    function CompareDate() {
        debugger;
        var fromDate = document.getElementById("fromtxtbox").value; (line 289)
        var toDate = document.getElementById("totextbox").value;
        var endDate = new Date(toDate);
        var startDate = new Date(fromDate);

        if (fromDate != '' && toDate != '' && startDate > endDate) {
            alert('end date should be greater than or equal to start date');
            document.getElementById('totextbox').value = "";
            return false;
        }
        else if (fromDate == '') {
            alert('Please enter start date!');
            document.getElementById('fromtxtbox').focus();
            return false;
        }
        else if (toDate == '') {
            alert('Please enter end date!');
            return false;
        }
        else if (fromDate == '' && endDate != '') {
            alert('please select from date!');
            return false;
        }
    }

</script>

<asp:MultiView ID="MultiView1" runat="server" ActiveViewIndex="0">
    <asp:View ID="view1" runat="server">


        <table align="left" cellspacing="5" width="590">
            <tr>
                <td colspan="3" style="background-color: #D3D8DE;">
                    <table cellpadding="0" cellspacing="0"
                        style="border-top: 1px solid rgb(51, 102, 204);" width="100%">
                        <tr>
                            <td style="height: 9px">&nbsp;Advanced Search</td>
                        </tr>
                    </table>
                </td>
            </tr>
            <tr>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
            </tr>
            <tr id="sc" runat="server">
                <td align="right">Select Classified</td>
                <td>:</td>
                <td>
                    <asp:RadioButton ID="radiobtnclass" runat="server" Text="class" GroupName="q"
                        AutoPostBack="True" Checked="True" ValidationGroup="1" />
                    <asp:RadioButton ID="radiobtnDemo" runat="server" GroupName="q" Text="demo"
                        AutoPostBack="True" ValidationGroup="1" />
                    &nbsp;<asp:Label ID="Label1" runat="server" Text="Select Demo/Class"
                        Visible="False" ForeColor="#FF3300"></asp:Label></td>
            </tr>
            <tr>
                <td align="right">Category </td>
                <td>:</td>
                <td>

                    <asp:DropDownList ID="ddcategory" runat="server" Width="120px" Height="20px"
                        AutoPostBack="True" OnSelectedIndexChanged="ddcategory_SelectedIndexChanged1">
                        <asp:ListItem Value="--select All--">--select All--</asp:ListItem>
                        <asp:ListItem Value="Software Training">Software Training</asp:ListItem>
                        <asp:ListItem Value="Call Center/BPO">Call Center/BPO</asp:ListItem>
                        <asp:ListItem Value="Non-IT Training">Non-IT Training</asp:ListItem>
                        <asp:ListItem Value="Medical Transcription">Medical Transcription</asp:ListItem>
                        <asp:ListItem Value="Spoken English">Spoken English</asp:ListItem>
                    </asp:DropDownList>
                </td>
            </tr>
            <tr>
                <td align="right">Course Name</td>
                <td>:</td>
                <td>
                    <asp:DropDownList ID="ddcoursename" runat="server" Width="120px" Height="20px">
                    </asp:DropDownList>
                </td>
            </tr>
            <tr>
                <td align="right">City</td>
                <td>:</td>
                <td>
                    <asp:DropDownList ID="ddcity" runat="server" Width="120px">
                    </asp:DropDownList>
                </td>
            </tr>
            <tr>
                <td align="right">Date</td>
                <td>:</td>
                <td>From&nbsp;&nbsp;
                    <asp:TextBox ID="fromtxtbox" runat="server"></asp:TextBox>
                    <cc1:CalendarExtender ID="fromtxtbox_CalendarExtender" runat="server"
                        Enabled="True" TargetControlID="fromtxtbox" PopupPosition="TopLeft">
                    </cc1:CalendarExtender>
                    To<asp:CompareValidator ID="tocomparevalidator" runat="server"
                        ControlToCompare="totextbox" ControlToValidate="fromtxtbox" Display="Dynamic"
                        ErrorMessage="Selected date should be greater than or equal to From date"
                        Operator="LessThanEqual" Type="Date"
                        OnDataBinding="Page_Load" ValidationGroup="a"></asp:CompareValidator>
                    <asp:TextBox ID="totextbox" runat="server"></asp:TextBox>
                    <cc1:CalendarExtender ID="totextbox_CalendarExtender" runat="server" Enabled="True"
                            TargetControlID="totextbox" PopupPosition="TopRight">
                    </cc1:CalendarExtender>
                </td>
            </tr>

            <tr>
                <td colspan="3" align="center" style="height: 35px">&nbsp;
        <br />
                    <asp:Button ID="advancesearch_btn" runat="server" Text="search"
                        OnClick="Button1_Click" OnClientClick="javascript:return CompareDate();" ValidationGroup="a" />
                    <asp:Label ID="Label22" runat="server" Text="Label" Visible="False"></asp:Label>
                    <asp:Label ID="Label21" runat="server" Text="Label" Visible="False"></asp:Label>
4

1 回答 1

0

改变 <asp:TextBox ID="fromtxtbox" runat="server"></asp:TextBox>

到: <asp:TextBox ID="fromtxtbox" ClientIDMode="Static" runat="server"></asp:TextBox>

如果您查看页面的源代码,您会发现 span 控件的 Id 属性不是“fromtxtbox”

于 2013-08-20T06:45:59.840 回答