AjaxControlToolkit CalendarExtender - Incorrect Date / Time Error?

I have a problem with AjaxControlToolkit CalendarExtender . Let me explain my page settings. I have an ASP TextBox on a page that should hold the end time of the event. The time should be in the format "MM / dd / yyyy hh: mm: ss tt" (i.e. "11/06/2011 11:59:59 PM").

Here's what the page layout looks like:

Link to AjaxControlToolkit at the top of the page.

 <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajax" %> 

The corresponding layout on the page:

 <asp:Label ID="_lblEventEndTime" runat="server" Text="End Time:" /> <asp:TextBox ID="_txtEventEndTime" runat="server" /> <asp:ImageButton ID="_imgbtnEventEndTime" runat="server" ImageUrl="~/Images/Calendar.png"/> <ajax:CalendarExtender ID="_cldrextEndDate" runat="server" CssClass="CalendarTheme" PopupButtonID="_imgbtnEventEndTime" TargetControlID="_txtEventEndTime" Format="MM/dd/yyyy hh:mm:ss tt" /> 

And the C # code behind:

 protected void Page_Load(object sender, EventArgs e) { DateTime nov6 = new DateTime(2011, 11, 6, 23, 59, 59); _txtEventEndTime.Text = nov6.ToString("MM/dd/yyyy hh:mm:ss tt"); } 

Now, for some reason, I was only able to reproduce this error on November 6, 2011 . But, as you can see on the Page_Load page, I set the time to "23:59:59", which is equal to "11:59:59 PM". However, when the page returns, the text box says "11/06/2011 10 : 59: 59 PM" instead of "11/06/2011 11:59:59 PM"

Now here's where everything is weird. If I remove CalendarExtender from the page, everything will work fine and the page will load as expected with the correct value in the TextBox. Which is also strange if I changed the FormatString for CalendarExtender to

 Format="MMMM/dd/yyyy hh:mm:ss tt" 

the page loads with the correct value - the only problem here now, when I actually click on my ImageButton calendar and use CalendarExtender, it will put the DateTime in the TextBox in the format "November / 06/2011 12:00:00 AM" (but this is expected) .

Now, if I changed the DateTime in the code behind

 DateTime nov6 = new DateTime(2011, 11, 6, 22, 59, 59); 

The text box will return as "11/06/2011 09 : 59: 59 PM", but it should read "11/06/2011 10:59:59 PM".

Why am I confused why CalendarExtender is interfering with my TextBox Control. It is almost as if the calendar expands on the fact that the clock goes from 1-24 instead of 0-23. Is there some kind of error with CalendarExtender that I don't know about?

PS All of these controls are on the test page, so there is nothing to stop them.

+4
source share
1 answer

I tried the same settings on my machine and it worked for me. Perhaps you are testing the page on another server / machine, which probably follows a different time zone. Make sure you use the code locally on your physical machine. Check and let us know.

0
source

Source: https://habr.com/ru/post/1381492/


All Articles