Jul 25, 2013, 6:32 PM
-
-
Jul 26, 2013, 3:01 AMAs you can read in this thread: http://social.msdn.microsoft.com/For...ed-on-timezone
The problem is that I don't care about time, just want the date (short date i.e. 5/31/2011). In my case the date is stored as 5/31/2011 0:00:000.00 in SQL. When my web service is called from a timezone that is -3 hours from the servers timezone, the client's date becomes 5/30/2011 9:00 PM and the client code is using the short date part only so 5/31/2011 is now 5/30/2011. This is obviously causing problems.
turn the date into a string on the service side. This string will use the server's timezone. And since now it is merely a string, the client will see it as is. You can do that inside your service. You don't need to modify the database.Last edited by Baidaly; Jul 26, 2013 at 3:54 AM. -
Jul 26, 2013, 11:53 AM
-
Jul 26, 2013, 12:09 PMIs the grid empty at all or the DATAHORA column only?
Please try to replace
with{ name: 'DATAHORA', type: 'date', dateFormat: "MS" }
{ name: 'DATAHORA', type: 'date', dateFormat: "c" }
-
Jul 26, 2013, 12:13 PMNo! All grid is empty... No records loaded in grid!
Thanks -
Jul 26, 2013, 1:11 PMASP.NET WebService deserializes it and we cannot affect it. You are not confined to use the Paging class, but you will get the same result without it.
This is also not a solution
Return Ext.Net.JSON.Serialize(paging)
I think the following could be a solution.
Here is a full example.[WebMethod] public object GetData() { return new { data = JSON.Serialize(data), // not a Paging instance here. In your case it should be "list.AsEnumerable" which you passed to the Paging constructor in the DataTableToPaging method total = 2 }; }
Page
WebService<%@ Page Language="C#" %> <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %> <!DOCTYPE html> <html> <head runat="server"> <title>Ext.NET v2 Example</title> </head> <body> <form runat="server"> <ext:ResourceManager runat="server" /> <ext:GridPanel ID="GridPanel1" runat="server"> <Store> <ext:Store runat="server"> <Model> <ext:Model runat="server"> <Fields> <ext:ModelField Name="test" /> <ext:ModelField Name="date" Type="Date" /> </Fields> </ext:Model> </Model> <Proxy> <ext:AjaxProxy Url="WebService1.asmx/GetData" Json="true"> <ActionMethods Read="POST" /> <Reader> <ext:JsonReader Root="d.data" TotalProperty="d.total" /> </Reader> </ext:AjaxProxy> </Proxy> </ext:Store> </Store> <ColumnModel runat="server"> <Columns> <ext:Column runat="server" Text="Test" DataIndex="test" /> <ext:DateColumn runat="server" Text="Date" DataIndex="date" /> </Columns> </ColumnModel> </ext:GridPanel> </form> </body> </html>
This way this setting should affect.using System; using System.Web.Services; using Ext.Net; namespace Work2 { [WebService(Namespace = "http://tempuri.org/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] [System.ComponentModel.ToolboxItem(false)] [System.Web.Script.Services.ScriptService] public class WebService1 : System.Web.Services.WebService { [WebMethod] public object GetData() { return new { data = JSON.Serialize(new object[] { new { test = "test1", date = DateTime.Today }, new { test = "test2", date = DateTime.Today.AddDays(1) } }), total = 2 }; } } }
By the way, you could avoid such problems using, for example, an ASHX handler instead of a WebService.Ext.Net.JSON.GlobalSettings.DateTimeZoneHandling = Newtonsoft.Json.DateTimeZoneHandling.Local
http://localhost:51297/#/GridPanel/P...rting/Handler/
Is there a specific reason why you picked up a WebService?Last edited by Daniil; Jul 26, 2013 at 1:53 PM. -
Jul 26, 2013, 4:44 PMDaniil! Thanks a lot for your help!!! I think that expensive for you show me a trail! Thanks again!
No reason for webservices... I belived it was the right way to integrate client and the server...
Why I could avoid such problems using ASHX handler instead of a WebService?
Excuse me for being so stupid in this matter! -
Jul 26, 2013, 5:19 PMWell, using WebServices is good to wire up server and client. Unless you run into such issues.
Well, an ASHX handler doesn't serialize the things automatically. You will be forced to serialized it manually. So, more room for flexibility. And JSON.Serialize() is nice to use for that. -
Jul 26, 2013, 5:33 PMOk!
I will follow the trail that you showed to me!
Thanks a lot, Daniil!!! -
Oct 31, 2013, 12:55 PMSorry I am very late to this thread. The other thing to bear in mind is that ASMX WebServices uses the DataContractJsonSerializer, not Json.NET. I remember stumbling onto this while writing the book. Here's what I wrote (sorry, not plugging the book, just remembered it was in there!)
p.147:
If we looked at the result, we would see something odd-looking, for example, /Date(1335752521448)/.
If the response from the server was a string, or a number, there'd be no problems here. Dates from ASMX Web Services, however, are a bit more involved.
Unfortunately, JSON doesn't specify a standard way to represent dates, while strings and numbers are fine. The JSON serialization used by ASMX services (DataContractJsonSerializer) creates a date using a pattern that was initially designed to be consumed by its own client-side AJAX library.
However, we are using Ext.NET and Ext JS, so we would have to handle this difficult-to-debug format manually. We can use Ext JS's client-side Date formatting API, for example, Ext.Date.parseDate("/Date(1335752521448)/", 'MS') which will give you back a JavaScript date object.
Alternatively, you could configure your service to return the date as a string that can be parsed when needed. Unfortunately, there is still no one way for JSON to agree and handle dates but at least there are some options here.
Hope that helps.
Similar Threads
-
[CLOSED] Specify how object is serialized in DirectMethod
By jchau in forum 2.x Legacy Premium HelpReplies: 1Last Post: Jan 12, 2013, 7:18 PM -
[CLOSED] Dates & Json & ComboBoxes
By PhilG in forum 1.x Legacy Premium HelpReplies: 3Last Post: May 24, 2012, 2:45 PM -
Help with JSON and Dates, driving me crazy, sample included
By paul-2011 in forum 1.x HelpReplies: 10Last Post: Aug 01, 2011, 1:58 PM -
ASP.NET JSON Formatted Dates and Formatting in GridPanel
By niceguymattx in forum 1.x HelpReplies: 3Last Post: May 11, 2010, 4:47 AM -
Problem with disable dates, when using culture setting
By Jurke in forum 1.x Legacy Premium HelpReplies: 5Last Post: Feb 26, 2009, 9:25 AM