简体   繁体   中英

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

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();
});
<input id="datepicker0" type="text" name="datepickernm"/> 

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

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

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.

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

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.

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