javascript 如何在代码隐藏中为 Datepicker 设置日期/获取日期

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9032068/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 05:23:19  来源:igfitidea点击:

How to set a date/ get a date for Datepicker in codebehind

c#javascriptjqueryasp.netdatepicker

提问by

I can't manage to set a date and to get a date of Datepicker in code behind(C#) does anyone have informations to give me about this ? thanks in advance!

我无法在后面的代码(C#)中设置日期和获取 Datepicker 的日期有没有人有关于这个的信息给我?提前致谢!

  <input id="datepicker" value="01/01/2011" type="text"/>



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

回答by Saurabh

<input id="datepicker0" type="text" name="datepickernm"/> 

You can get the value from below code in the codebehind:

您可以从代码隐藏中的以下代码中获取值:

String text = Page.Request.Form["datepickernm"]

回答by Rey Rahadian

Use an ASP textbox control:

使用 ASP 文本框控件:

<asp:textbox runat="server" id="txtDate"/>

<script type="text/javascript">
  $('#<%= txtDate.ClientID %>').datepicker();
</script>

This way you could get and set the value from code behind.

这样你就可以从后面的代码中获取和设置值。

回答by DarthCoder

The Calendar control in asp.net will provide you with the functionality you need. Drag the control from the Toolbox in Visual Studio

asp.net 中的日历控件将为您提供所需的功能。从 Visual Studio 的工具箱中拖动控件

then access the Calendar control from codebehind using the ID

然后使用 ID 从代码隐藏访问日历控件

回答by Patrick Chia

The above method does not allow me to set the value from the code behind. I am only able to get the date from the code behind.

上面的方法不允许我从后面的代码中设置值。我只能从后面的代码中获取日期。

When i remove the javascript form the html header, it seems to works.. i think that the javascript is overriding the value in the textbox.

当我从 html 标题中删除 javascript 时,它似乎有效..我认为 javascript 覆盖了文本框中的值。