简体   繁体   English

带有jQuery DatePicker的ASP.NET

[英]ASP.NET with jQuery DatePicker

I would like to do something like this: http://jqueryui.com/datepicker/ 我想做这样的事情: http : //jqueryui.com/datepicker/

However, I'm not exactly sure how: 但是,我不确定如何:

  1. I have a masterpage-content page, and when I tried to copy that code and paste them into the content page, it will say "XXXX cannot be in the content region". 我有一个主页内容页面,当我尝试复制该代码并将其粘贴到内容页面时,它将显示“ XXXX不能在内容区域中”。
  2. When the user hit the submit button, how am I going to pass the date in the textbox to the server side code? 当用户单击“提交”按钮时,如何将textbox的日期传递给服务器端代码?

Here are parts of my code: 这是我的代码的一部分:

.aspx: .aspx:

<asp:Content ID="Content4" ContentPlaceHolderID="MainContent1" runat="server">
    <p>Date: <input type="text" id="datepicker"></p>
    <asp:Button ID="btnSubmit" runat="server" Text="Submit" />
    <asp:Label ID="lblOutput" runat="server" Text="Label"></asp:Label>
</asp:Content>

.cs: .cs:

protected void btnSubmit_Click(object sender, EventArgs e)
{
    lblOutput.Text = //The date from the datepicker
}

You need to use the runat="server" like this in your html: 您需要在html中像这样使用runat="server"

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

Then on your server side your can refer to datepicker as a server object and access datepicker.Value . 然后,在服务器端,您可以将datepicker称为服务器对象,并访问datepicker.Value

To @CJ comment. 给@CJ评论。 This is the source code included on this link added on the question, it is there where the runat=server goes: 这是问题上添加的此链接上所包含的源代码,在此处runat=server可以到达:

This goes on your Master Page : 这在您的母版页上

<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
<link rel="stylesheet" href="/resources/demos/style.css">

This goes on your Content Page : 这在您的内容页面上

<p>Date: <input type="text" id="datepicker" class="datepicker"></p>
<script>
  $(document).on('ready',function() {
    $( ".datepicker" ).datepicker();
  });
</script>

HTML5使用type="date"

<asp:TextBox ID="tbDate" runat="server" type="date"></asp:TextBox>

You need to initialize your datepicker and add runat="server" to your input like this: 您需要初始化日期选择器,并将runat="server"添加到您的输入中,如下所示:

$(function() {
   $("#datepicker").datepicker();
});


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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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