I am building an ASP.NET website, and in the aspx markup page i put in a JQuery datepicker. I also set default values, and on the FE side it looks ok, the text box is always populated with the selected date. However when im trying to use the text values in the text box, it acts like there's nothing there.
This is my JS function in the ASPX page
<script type="text/javascript">
$(function () {
//console.log($("[id$=txtFromDate]"));
//console.log($("[id$=txtToDate]"));
$("[id$=txtFromDate]").datepicker();
$("[id$=txtToDate]").datepicker();
//init date format
$("[id$=txtFromDate]").datepicker({ dateFormat: 'mm/dd/yy' });
$("[id$=txtToDate]").datepicker({ dateFormat: 'mm/dd/yy' });
//init default date
var FromDate = new Date();
FromDate.setMonth(FromDate.getMonth()-1)
$("[id$=txtFromDate]").datepicker('setDate',FromDate);
$("[id$=txtToDate]").datepicker('setDate','today');
});
How can i work with the datepicker from the code-behind C#?
Replace
$("[id$=txtToDate]").datepicker('setDate','today');
with
var Today = new Date();
$("[id$=txtToDate]").datepicker('setDate',Today);
and then in code behind you can use this code
Request.Form["txtToDate"]
"txtToDate" is your input box Name and don't use input box id;
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.