|
Member
|
johnny-segment
-
1/24/2011 9:41:13 AM
Date & Time Property in Web-part - not saving
I've created a new web-part/widget and assigned a new property ‘StartDate’ (Attribute Type: Date & Time, Field Type: Calendar)
Throughout the CMS we have set the culture to en-GB and have set this for the user profiles. We also have this set in the globalisation settings in the Web.Config. I’ve also set the database to use a default language of ‘British English’
In the Page tab of the CMS Desk, when I add this new web-part/widget, we get the widget properties window, with the date property and calendar icon/date picker. When a date is selected it is displayed in ‘DD/MM/YYYY’ format, which is what we want, but unfortunately this does not save in the database because the value is not recognised as a valid date. The database must be expecting ‘MM/DD/YYYY’ format and does not recognise the date (e.g. 24/01/2011) as a valid date.
Is there somewhere else we need to change the culture?
The SQL login/user is set to British English, IIS is set to use British English, and throughout Kentico we have changed the content/UI culture to English – UK/ British English /en-GB where possible.
Can you let us know what else we need to change? We’ve trawled the documentation, but unfortunately to no avail.
Thanks!
|
|
|
Kentico Developer
|
kentico_ivanat
-
1/26/2011 2:20:48 AM
RE:Date & Time Property in Web-part - not saving
Hi, Could you please share the datetime property code of your custom webpart? I tried to reproduce the issue, i.e set preferred UI culture to en-GB to make the datetime formatted: day/month/year. The database default culture was en-US. Using following code: public DateTime DateToStore { get { return ValidationHelper.GetDateTime(GetValue("Date"),new DateTime(2011,1,1)); } set { SetValue("Date", value); } }
and adding the new property with codename Date in Site Manager - Development - Webparts - my webpart - Properties (the Date property had an Attribute type: Date and time, Field type: Calendar ), the datetime value was stored in the database without any issue. Best regards, Ivana Tomanickova
|
|
|
Member
|
johnny-segment
-
1/27/2011 2:53:21 AM
RE:Date & Time Property in Web-part - not saving
Thanks for the reply.
The web part we have had no custom code on it. It was an empty .ascx file prepped for Kentico use. All the issues we have are in the Kentico interface alone.
These are the steps of what we did:
1. Created and added the blank web part to Kentico (Site Manager > Development > Web Parts) 2. Added to date and time properties to the web part – both used a field type of Calendar 3. Switched to CMS Desk 4. Added the web part to a page 5. We used the pop-up date pickers and noticed the selected dates were displayed in the web part propertied edit window in US format (MM/dd/yyyy) (en-US) 6. We went through Kentico and changed the culture and UI culture settings to use British English (en-GB) 7. The web part edit window now displayed selected dates in UK format (dd/MM/yyyy) which is what we wanted 8. The issue that arises, is that if we select a date of 25/01/2011 – it is not saved by Kentico, as it must be expecting this to be in US format somewhere (i.e. 25 is not a valid month number). If we add a date of 05/01/2011 it is saved by Kentico, presumably because this is a valid US date.
We’re not doing any front-end work in our web-part at the moment – this is all happening in the CMS. Can you tell us what we need to change to ensure dates are displayed in Kentico in UK format, and also can be stored successfully in the database.
Thanks
|
|
|
Kentico Developer
|
kentico_ivanat
-
1/27/2011 9:05:20 AM
RE:Date & Time Property in Web-part - not saving
Hi, could you please show us the code of your webpart (or send me an export on support@kentico.com with reference to this thread). It was an empty .ascx file prepped for Kentico use. All the issues we have are in the Kentico interface alone.
Does it mean that you did not modified the ascx code of the webpart? Because if you added a new field in Site Manager - Development - webpart - your new webpart - Fields - you need to modify the code behind of the webpart as well. Please see more details here: developing custom webpartsMissing property definition in the code behind is probably a reason why the date time value is not stored correctly in the database. If it is not your case please share the code of your webpart to provide you more information. Best regards, Ivana Tomanickova
|
|
|
Member
|
johnny-segment
-
1/27/2011 10:08:59 AM
RE:Date & Time Property in Web-part - not saving
Hi Ivana,
Thanks for the reply. I mentioned above that there is as yet no code in the web part to send you.
At the moment it is a blank/new .ascx file.
The issue we are having is in Kentico CMS Desk. When we add the blank web part to a page, and configure it to edit the properties - it will not save the date when it is in UK format. We enter 25/01/2011 and it will not save - it saves an empty string.
See the images below...
http://img585.imageshack.us/i/img1uv.jpg/ - we set-up a new webpart http://img268.imageshack.us/i/img2ee.jpg/ - we edit the date http://img198.imageshack.us/i/img3km.jpg/ - we choose a date (Kentico is set to use en-GB for it's UI and CMS etc) http://img253.imageshack.us/i/img4qr.jpg/ - a date is entered in UK format, which correct - but Kentico WILL NOT save it...it only saves an empty string. If we enter a US format, it saves (e.g. MM/dd/yyyy)
We have changed every culture/language setting in kentico (and the web.config) to use en-GB - but it still won't save. The database/database user is also set to British English (en/GB)
What can we do to fix this?
Thanks!!
|
|
|
Kentico Developer
|
kentico_ivanat
-
1/27/2011 11:05:32 AM
RE:Date & Time Property in Web-part - not saving
Hi, Thank you for screenshots. What I have tried to say is that the selected value (in properties of the webpart - in CMS Desk) cannot be set in the database unless you create appropriate code in the code behind of the webpart. To insert date value into database successfully it is not enough to create a property (img1). These properties have to be set in the code behind of webpart. In your case there should be something like:
public DateTime DateToStore { get { return ValidationHelper.GetDateTime(GetValue("EventStartDate"),new DateTime(2011,1,1)); } set { SetValue("EventStartDate", value); } }
This code is not created automatically when you add a new property field in the Site Manager. Please take a look at the link from my previous post describing how to create a custom webpart as well. Best regards, Ivana Tomanickova
|
|
|
Member
|
johnny-segment
-
1/28/2011 3:25:40 AM
RE:Date & Time Property in Web-part - not saving
Thanks, we are now about to store the date.
We can now save the date in the correct format...but when you open the Web Part edit window again the date is not displayed in the Kentico form (although it has been saved) - is there another coded property to ensure the date is displayed in the Kentico web-part edit form?
I should point out that 'DateToStore' is not documented anywhere in the Kentico developer or web-parts documentation, the Kentico knowledge base, and only appears in this thread when you run a search here.
Will this be documented in the future?
Many thanks.
|
|
|
Member
|
johnny-segment
-
1/28/2011 4:42:31 AM
RE:Date & Time Property in Web-part - not saving
Ok, here's where we're at now....
We add the web-part, change the dates, and save it:
http://img8.imageshack.us/i/imgnew1.jpg/
Then we can see on the page, that the web part has saved the dates, and is displaying them correctly (we're displaying the month / day only to the front-end user):
http://img26.imageshack.us/i/imgnew2.jpg/ - they have been stored and are working!!
Then, we edit the web-part to change some of the information and the DATES ARE NOT POPULATED:
http://img812.imageshack.us/i/imgnew3.jpg/
What do we need to change to allow the fields to be populated on an edit?
This seems like something that should happen automatically (esp. as the Title and ID are being saved, stored and populated ok - we're not having to do any coding for that)
Thanks!!
|
|
|
Kentico Developer
|
kentico_ivanat
-
1/28/2011 5:35:30 AM
RE:Date & Time Property in Web-part - not saving
Hi,
I have tried to reproduce the issue with the code I sent you in previous post, but datetime field was set after I reopened properties of the webpart.
Could you please show me the code of your webpart, please?
Best regards, Ivana Tomanickova
|
|
|
Member
|
johnny-segment
-
1/28/2011 5:56:07 AM
RE:Date & Time Property in Web-part - not saving
Ok, here's the code. I just created a new web-part with ONLY a date-time property and got the same result. It lets me set it, but when I go to edit, it's not populated. Remember I have the whole UI/web.config etc set to use en-GB. The front end only displays the literals of the data. The .cs code: using System; using System.Web.UI; using System.Threading; using System.Globalization;
using CMS.PortalControls; using CMS.GlobalHelper;
public partial class CMSWebParts_MyKenticoSite_ucTest : CMSAbstractWebPart {
#region "Properties"
public DateTime DateToStore { get { return ValidationHelper.GetDateTime(GetValue("EventStartDate"), new DateTime(2011, 1, 1)); } set { SetValue("EventStartDate", value); } }
#endregion
protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) LoadOverview(); }
private void LoadOverview() { litEventTitle.Text = GetValue("EventTitle").ToString(); DateTime dtStart = Convert.ToDateTime(GetValue("EventStartDate").ToString()); DateTime dtEnd = Convert.ToDateTime(GetValue("EventEndDate").ToString()); litEventDate.Text = "<div class='double-date'><span class='month tc bc-color'>" + dtStart.ToString("MMM").ToUpper() + "<br />" + dtStart.ToString("dd").ToUpper() + "</span><span class='day bc'>" + dtEnd.ToString("MMM").ToUpper() + "<br />" + dtEnd.ToString("dd").ToUpper() + "</span></div>"; }
}
|
|
|
Kentico Developer
|
kentico_ivanat
-
1/28/2011 8:02:53 AM
RE:Date & Time Property in Web-part - not saving
Hi, Thank you for the code. I finally reproduced the issue with British culture. Regrettably, this seems to be a bug in the current version. I'm very sorry for this inconvenience. We will try fix it in the nearest version or in the next hotfix package for this particular Kentico CMS version. Best regards, Ivana Tomanickova
|
|
|
Member
|
johnny-segment
-
1/28/2011 8:55:46 AM
RE:Date & Time Property in Web-part - not saving
Hi Ivana,
Thanks for letting me know, and thanks for looking into this for me.
I guess we'll have to use en-US for now :)
Thanks,
JS
|
|
|