ASP.NET使用jQuery的DatePicker [英] ASP.NET with jQuery DatePicker

查看:148
本文介绍了ASP.NET使用jQuery的DatePicker的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我愿做这样的事情: http://jqueryui.com/datepicker/

不过,我不完全知道如何:


  1. 我有一个母版内容页,当我试图复制code,并将其粘贴到内容页面,它会说:XXXX不能在内容区。

  2. 当用户点击提交按钮,我应该如何去通过在文本到服务器端code中的日期?

下面是我的code部分:

的.aspx:

 < ASP:内容ID =Content4ContentPlaceHolderID =MainContent1=服务器>
    < P>日期:<输入类型=文本ID =日期选择器>< / P>
    < ASP:按钮的ID =btnSubmit按钮=服务器文本=提交/>
    < ASP:标签ID =lblOutput=服务器文本=标签>< / ASP:标签>
< / ASP:内容>

的.cs:

 保护无效btnSubmit_Click(对象发件人,EventArgs的发送)
{
    lblOutput.Text = //将在日期选择日期
}


解决方案

您需要使用 =服务器像这样在你的HTML:

 <输入类型=文本ID =日期选择器=服务器>

然后在你的服务器端您可以参考日期选择器作为服务对象和访问 datepicker.Value

要@ C.J评论。这是包括在这个链接 http://jqueryui.com/datepicker/ 上加这个问题,这是那里的 RUNAT =服务器云:

这下去你的主页

 <脚本的src =// code.jquery.com / jQuery的-1.10.2.js>< / SCRIPT>
  <脚本的src =// code.jquery.com / UI / 1.10.4 / jQuery的-ui.js>< / SCRIPT>
  <链接rel =stylesheet属性HREF =/资源/演示/ style.css文件>

这下去你的内容页

 < P>日期:<输入类型=文本ID =日期选择器类=日期选择器>< / P>
 <脚本>
  $(文件)。在('准备好',函数(){
    $(.datepicker).datepicker();
  });
  < / SCRIPT>


I would like to do something like this: 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".
  2. When the user hit the submit button, how am I going to pass the date in the textbox to the server side code?

Here are parts of my code:

.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:

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:

<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

To @C.J comment. This is the source code included on this link http://jqueryui.com/datepicker/ added on the question, it is there where the runat=server goes:

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>

这篇关于ASP.NET使用jQuery的DatePicker的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆