I have to implement a jquery DateTimePicker.Below is the code I have written for it on aspx page. Here on a button(btnDialog) a dialog which has some text and textbox(myDate).The datepicker appears fine and sets selected value in textbox.But when ok button is clicked after the onClientClick event the server side onClick event is not being called. Kindly let me know where i could be wrong.
<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;
}