I spent more time than I will EVER admit trying to figure out what the heck was wrong with my code, passing a date created by the jQuery UI datepicker into my .NET WCF service. I tried tick conversions (which would wind up sending a date WCF didn’t understand). The only things I COULD get WCF to understand, read around the year 1970. So, with a bit of research, I woudn up with the following code to convert a javascript date to a format that WCF wants to see.
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "/WebServices/WebServiceHost.svc/scorePhotographer",
data: '{"datevisited": "\\\/Date(' + Date.UTC(x.getUTCFullYear(), x.getUTCMonth(), x.getUTCDate(), x.getUTCHours(), x.getUTCMinutes(), x.getUTCSeconds(), x.getUTCMilliseconds()) +
(-x.getTimezoneOffset() < 0 ? '-' : '+') + (Math.abs(x.getTimezoneOffset() / 60) < 10 ? '0' : '') + (Math.abs(x.getTimezoneOffset() / 60)) + '00' +
')\\\/" +
'"}',
dataType: "json",
dataFilter: function(data, type) {
var d = data.replace(/"\\\/(Date\(.*?\))\\\/"/gi, 'new $1');
return d;
},
success: function (msg) {
// blah
},
error: function (e) {
//blah
}
});
Hope this helps someone!
It’s been awhile, but I’ve finally got some updates released. You will find:
- the 24 hour mode works as expected now
- CSS has been altered to include positioning fixes for the colons in IE8 and FF 3.6
- issues have been addressed for problems that manifest themselves when there are multiple pickers on a page and you try to change focus and change time
Thanks!
I had a situation where I needed to do this recently. I googled of course, and came up with an overloaded FindControl method. I implemented this in my code, and all seemed well. UNTIL… came the time to get the data posted from my control. I had controls nested in a UserControl, and that usercontrol nested within a FormView. When the postback occurred, I was able to retrieve all values from controls directly in the formview but none from within the controls inside my usercontrol. A buddy of mine helped me out on this, and believe me.. it was no fun tracking down. the values “not being posted” was actually a flaw in the FindControl method override. Please use this piece of code in the naming container that your validators reside, if they in fact need to validate against controls outside:
protected override Control FindControl(string id, int pathOffset)
{
Control c = base.FindControl(id, pathOffset);
if (c != null)
return c;
return FindControl(Page, id);
}
public Control FindControl(Control parent, string id)
{
Control recurse;
if (parent.ID == id)
{
return parent;
}
foreach (Control child in parent.Controls)
{
recurse = FindControl(child, id);
if (recurse != null)
{
return recurse;
}
}
return null;
}
As requested, I added functionality to the time picker to allow the up and down arrows on the keyboard to increase and decrease the values in the hours, minutes, seconds, and toggle the AM/PM box. I’ve also made the semi-colon seperators unfocusable.
Recent Comments