You may use this common js function for converting js date format "dd/mm/yyyy" to db format "mm/dd/yyyy" before db update.
The function is also desinged to help resolve the date field readonly problem.
As follows:
Common js file: common.js
// get element object in a page by its name/id
function dg(objName){
return document.getElementById(objName);
}
// copy the value of a readonly textbox to its corresponding hidden field for submission
function copyHiddenValue(objName){
try{
var tmp = dg(objName).value;
// convert date from "dd/mm/yyyy" to "mm/dd/yyyy"
// for db update
tmp = tmp.substr(3,2)+ "/" + tmp.substr(0,2) + "/" + tmp.substr(6,4);
dg(objName+"Hidden").value = tmp;
}catch(e)
{}
}
aspx file:
<script language="javascript" src="../Scripts/common.js"></script>
...
<asp:TextBox ID="txtAssignmentDate" ReadOnly="true" runat="server" MaxLength="10" ></asp:TextBox>
<img id="imgAssignmentDate" src="../Images/cal.gif" height="16" width="16" οnclick="displayDatePicker('txtAssignmentDate', false, 'dmy', '/');" />
<input id="txtAssignmentDateHidden" type="hidden" runat="server" />
...
...
aspx.cs file:
btnCreate.Attributes.Add("onClick", "copyHiddenValue('txtAssignmentDate');copyHiddenValue('txtEstLostDate');");
....
strEstLostDate = txtEstLostDateHidden.Value;
...
...