简体   繁体   中英

asp.net can't take the text of input text

This is my aspx

<p>Date: <input type="text" id="datepicker" >
        <asp:Button id="BookingForDate" runat="server" OnClick="BookingForDate_Click" Text="Search"/> </p> 
    <table id="DateBookingTable" runat="server" style="visibility:hidden">
        <tr><th>ID</th><th>PlanTime</th></tr>
    </table>

on my code in c# I can't see datepicker

why?

note please that i can take all the controllers from id except this one.

I already tried restart the visual studio

You have 2 options

add runat="server" to the input

<input type="text" id="datepicker" runat="server" />

or create an TextBox

<asp:TextBox runat="server" id="datepicker"></asp:TextBox>

You should add

runat="server"

to your input. No you are using an html control and not an asp.net server side control. Hence you can't access the value of the textbox the way you want.

So try the following and then you will be able to access the value of your textbox:

<asp:TextBox id="datepicker" runat="server"/>

Then in your code behind class you can access the value of this textbox

datepicker.Text

Another approach, as I pointed initially, it would be the following:

<input type="text" id="datepicker" runat="server">

您尚未为控件指定名称,还添加了runat =“ server”

<input type="text" id="datepicker" runat="server" name='datepicker' />

You forgot to add the runat -attribute to your input -tag. Try this:

<input type="text" id="datepicker" runat="server">

With that change, you should be able to access the element from code behind

See MSDN

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM