我必须实现一个jquery DateTimePicker.Below是我在aspx页面上为它编写的代码。 在一个按钮(btnDialog)上有一个对话框,其中包含一些文本和文本框(myDate)。日期选择器显示正常并在文本框中设置选定的值。但是当在onClientClick事件之后单击确定按钮时,服务器端onClick事件未被调用。 请告诉我可能出错的地方。
<div id="myDialog" title="Text Dialog">
<p>The textbox below should show the datepicker on focus, except for when the dialog opens.</p>
Enter date:
<asp:TextBox ID="myDate" runat="server" />
<asp:Button ID="BtnOk" runat="server" OnClick="BtnOk_Click" OnClientClick="return validatedate();" Text="Ok" />
<asp:Button ID="btnCancel" OnClientClick="return destroydialog();" runat="server" Text="Cancel"/>
</div>
<script type="text/javascript" language="javascript">
$(function() {
$('#btnDialog').click(function() {
$('#myDialog').dialog({
open: function() {
$( "#ctl00_MainContent_myDate" ).datepicker().blur();
},
close: function() {
$('#ctl00_MainContent_myDate').datepicker('destroy');
},
});
});
});
function destroydialog()
{
$("#myDialog").dialog("destroy");
return false;
}
function validatedate()
{
var undodate;
undodate=$("#ctl00_MainContent_myDate").val();
if (undodate.length > 0 && !isValidDate(undodate))
{
alert("Please enter date from which undo operation is to be performed.");
return false;
}
else
{
return true;
}
}
function isValidDate(undodate) {
//alert("currVal = " + currVal);
if (undodate == '')
return false;
var rxDatePattern = /^([1-9]|0[1-9]|1[012])[\/]([1-9]|0[1-9]|[12][0-9]|3[01])[\/]((19|20)\d\d)$/;
var dtArray = undodate.match(rxDatePattern); // is format OK?
if (dtArray == null)
return false;
//Checks for mm/dd/yyyy format.
dtMonth = dtArray[1];
dtDay = dtArray[2];
dtYear = dtArray[3];
if (dtMonth < 1 || dtMonth > 12)
return false;
if (dtDay < 1 || dtDay > 31)
return false;
if ((dtMonth == 4 || dtMonth == 6 || dtMonth == 9 || dtMonth == 11) && dtDay == 31)
return false;
if (dtMonth == 2) {
var isleap = (dtYear % 4 == 0 && (dtYear % 100 != 0 || dtYear % 400 == 0));
if (dtDay > 29 || (dtDay == 29 && !isleap))
return false;
}
return true;
}