Thx. I found a solution to work out.
How to get the value of DateTimePicker in the ASP.Net application?
I have an asp.net application in which master page is used as well as the DateTimePicker JS function.
<div class="col-sm-6" >
<input type="text" id="datetimepicker" />
</div>
<script type="text/javascript" >
$("#datetimepicker").datetimepicker({
format: 'YYYY-MM-DD HH:mm',
locale: moment.locale('zh-CN'),
});
</script>
The idea is the Date information showed in the input control can be obtained and can be used as a parameter in the UploadShift function.
protected void btnUpload_Click(object sender, EventArgs e)
{
string dateTime = Request.Form["datetimepicker"];
DateTime endDate = Convert.ToDateTime(dateTime);
int result = shiftController.UploadShift(endDate);
}
The problem is the datetime information can not be retrieved every time. Please help me fix the issue.THX!!!
2 answers
Sort by: Most helpful
-
-
Yijing Sun-MSFT 7,061 Reputation points
2022-06-14T02:30:36.517+00:00 Hi @piglet ,
The problem is the datetime information can not be retrieved every time.
What means can not be retrieved every time? Do you get the value occasionally, but not every so often? As far as I think, the code behind can't get the value from the js datetimepicker. I suggest you could get the value using js and then use ajax to post to the code behind.
js like this:
code-behind:
[WebMethod] public static string Test(string tb) { DateTime endDate = Convert.ToDateTime(tb); int result = shiftController.UploadShift(endDate); return result.ToString(); }
Best regards,
Yijing Sun
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.