JQuery的日期选择器在ASP.NET [英] JQuery Date Picker in ASP.NET
问题描述
我在我的网页上的按钮。当我点击它,它应该打开一个jQuery窗口。
I have a button in my page. When I click it, it should open a JQuery window.
在窗口中,我有一个日期选择器控制,默认情况下应该显示当前日期。我的code是像这样。
Inside the window, I have a datepicker control, which by default should show the current date. My code is like so.
客户端
<script type="text/javascript">
$(function () {
$("#<%= txtDate.ClientID %>").datepicker({
changeMonth: true,
changeYear: true,
dateFormat: "dd-mm-yy",
yearRange: '1901:2050',
maxDate: new Date(),
showOn: "button",
buttonImage: "images/calendar.png",
buttonImageOnly: true,
showButtonPanel: true,
showMonthAfterYear: true,
inline: true,
altField: "#<%= HiddenDate.ClientID %>",
altFormat: "dd-mm-yy",
onSelect: function (dateText, inst) {
shouldsubmit = true;
},
onClose: function (dateText, inst) {
shouldsubmit = false;
javascript: __doPostBack('<%= txtDate.ClientID %>', '');
}
});
Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(function (evt, args) {
$("#<%= txtDate.ClientID %>").datepicker({
changeMonth: true,
changeYear: true,
dateFormat: "dd-mm-yy",
yearRange: '1901:2050',
maxDate: new Date(),
showOn: "button",
buttonImage: "images/calendar.png",
buttonImageOnly: true,
showButtonPanel: true,
showMonthAfterYear: true,
inline: true,
altField: "#<%= HiddenDate.ClientID %>",
altFormat: "dd-mm-yy",
onSelect: function (dateText, inst) {
shouldsubmit = true;
},
onClose: function (dateText, inst) {
shouldsubmit = false;
javascript: __doPostBack('<%= txtDate.ClientID %>', '');
}
});
});
服务器端
If Not Page.IsPostBack Then
TxtDate.Text = DateTime.Today.ToString("dd-MM-yyyy")
TxtDate.Text = Session("CurrentDate")
End If
但是,文本框保持空白。任何线索,我在哪里错了?
But the textbox remains blank. Any clues as to where I am wrong?
推荐答案
我已经解决了该问题。
问题是我不得不重新添加按钮的点击时间在我的code。因此,它并没有显示的日期。所以,我从页面加载模块去掉下面的code并将其添加到添加按钮单击事件后,我重新设置日期。
The problem was I had reset the date on click of the Add button in my code. Hence it didn't show the date. So I removed the following code from the page load block and added it to the Add button click event after I reset the date.
Protected Sub btnNewBatch_Click(sender As Object, e As ImageClickEventArgs) Handles btnNewBatch.Click
TxtDate.Text = DateTime.Today.ToString("dd-MM-yyyy")
TxtDate.Text = Session("CurrentDate")
HiddenDate.Value = TxtDate.Text
End Sub
感谢@Samit和@Yuriy您的时间和建议!
Thanks @Samit and @Yuriy for your time and suggestions!
这篇关于JQuery的日期选择器在ASP.NET的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!