开发者

Error: 'this._targetEl.value.length' is null or not an object ASP.NET

开发者 https://www.devze.com 2023-03-06 01:42 出处:网络
I\'m trying to bind the selected value from the date picker to an asp textbox but I have this Error: \'this._targetEl.value.length\' is null or not an object.

I'm trying to bind the selected value from the date picker to an asp textbox but I have this Error: 'this._targetEl.value.length' is null or not an object.

Here's the code:

<InsertItemTemplate>
    Book Title:
    <asp:DropDownList ID="DropDownList1" runat="server" 
        DataSourceID="booktitleDataSource" DataTextField="booktitle" 
        DataValueField="bookid" SelectedValue='<%# Bind("bookid", "{0}") %>'>
    </asp:DropDownList>
    <asp:SqlDataSource ID="booktitleDataSource" runat="server" 
        ConnectionString="<%$ ConnectionStrings:LibrarySystemConnectionString %>" 
        SelectCommand="SELECT [bookid], [booktitle] FROM [TblBooks]">
    </asp:SqlDataSource>
    <br />

    Employee PIN:
    <asp:TextBox ID="employeeidTextBox" runat="server" 
        Text='<%# Bind("employeeid") %>' />
    <br />

    Department:
    <asp:TextBox ID="departmentTextBox" runat="server" 
        Text='<%# Bind("department") %>' />
    <br />

    Date borrowed:
    <asp:TextBox ID="dateborrowedTextBox" runat="server" Text='<%# Bind("dateborrowed") %>' /> 
<%--<input type="text" name="dateborrowedTextBox" readonly="readonly" id="dateborrowedTextBox">--%> 
    <a href="#" onclick="cdp1.showCalendar(this, 'dateborrowedTextBox'); return false;">Date Picker</a>       
    <br />

    <asp:Button ID="InsertButton" runat="server" CausesValidation="True" 
        CommandName="Insert" Text="Insert" />
    <asp:Button ID="InsertCancelButton" runat="server" CausesValidation="False" 
        CommandName="Cancel" Text="Cancel" />
</InsertItemTemplate>

It was working when I tried using <input type="text" name="dateborrowed" readon开发者_StackOverflow中文版ly="readonly" id="dateborrowedTextBox"> but when I tried using the asp:TextBox I cant pass the selected value from date picker to the textbox. So where did I go wrong? Is there a way to program the date picker link to call the popup calendar? (its in Java btw)

Help would be much appreciated! Thanks in advance.


Nested controls have their ID/name attributes overwritten with an absolute unique id/name when rendered. When your javascript is attempting to reference the TextBox its name won't actually be 'dateborrowedTextBox' it will be something like '...$ctl00$dateborrowedTextBox'.

If your javascript is finding the control by name, this might clear up the issue:

<a href="#" onclick="cdp1.showCalendar(this, '<%#Container.FindControl("dateborrowedTextBox").UniqueID%>'); return false;">Date Picker</a>

Otherwise try this if its finding the control by id:

  <a href="#" onclick="cdp1.showCalendar(this, '<%#Container.FindControl("dateborrowedTextBox").ClientID%>'); return false;">Date Picker</a>


Found the solution. I think it can only read asp.net syntax not classic asp.

<asp:TextBox ID="reservedateTextBox" runat="server" Text='<%# Bind("reservedate") %>' />
<%--Date Picker--%>
<a href="#" onclick="cdp1.showCalendar(this,'ctl00$ContentPlaceHolder1$FormView2$reservedateTextBox'); return false;">Date Picker</a>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号