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

僤鯓⒐⒋嵵緔 提交于 2019-12-22 05:09:32

问题


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!

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



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

回答1:


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

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

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



回答2:


Use an ASP textbox control:

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




回答3:


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

then access the Calendar control from codebehind using the ID




回答4:


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.



来源:https://stackoverflow.com/questions/9032068/how-to-set-a-date-get-a-date-for-datepicker-in-codebehind

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!