Property issues

Vote:
 
I'm following the property example in the SDK for "Editing several properties with one control". I have some questions about this, at it seems not to work as intended. 1) The SDK example does not compile: Properties[Name] = _textbox1.Text; Properties[Name + "_extra1"] = _textbox2.Text; Properties[Name + "_extra2"] = _textbox3.Text; should be Properties[Name] = new PropertyString(_textbox1.Text); Properties[Name + "_extra1"] = new PropertyString(_textbox2.Text); Properties[Name + "_extra2"] = new PropertyString(_textbox3.Text); 2) The PropertyDataCollection is updated with the new keys and values, but it seems that this is not persited in the Database. When page is reloaded after saving, the properties are not in the collection anymore! A bug, or is there another way of persisting the data ? I tried to clone the PropertyDataCollection by using PropertyDataCollection clonedProperties = Properties.CreateWritableClone(); clonedProperties[Name + "BannerBackground"] = new PropertyString(_textboxBackgroundUrl.Text); clonedProperties[Name + "BannerWidth"] = new PropertyString(_textboxWidth.Text); clonedProperties[Name + "BannerHeight"] = new PropertyString(_textboxHeight.Text); but without luck. Any advice ?
#15886
Mar 25, 2008 19:07
Vote:
 
Regarding the codesample, the bad code has now been updated and will be published along with the next public version of the SDK. / Daniel Tempel
#16569
Mar 25, 2008 19:09
Vote:
 
Are you creating a writable clone of the PageData object you're working with? Take a look at the "PageData Cache" section here: http://www.episerver.com/en/EPiServer_Knowledge_Center/Documentation/TechNotes/CMS-Tech-Notes/Migrating-to-EPiServer-CMS/ -- Lars Øyvind Bodahl www.epinova.no
#16570
Mar 25, 2008 19:09
Vote:
 
Hi Lars Øyvind and thanks for the suggestion. I tried with a writable clone, but with no luck. My thoughts are that, when you are in edit mode, you are implicit working on a writable clone. But I might be wrong Here is the code I have tried without luck public override void ApplyEditChanges() { PageData writableClone = this.CurrentPage.CreateWritableClone(); writableClone.Property[Name + "BannerBackground"] = new PropertyString(_textboxBackgroundUrl.Text); writableClone.Property[Name + "BannerWidth"] = new PropertyString(_textboxWidth.Text); writableClone.Property[Name + "BannerHeight"] = new PropertyString(_textboxHeight.Text); /*PropertyDataCollection clonedProperties = Properties.CreateWritableClone(); clonedProperties[Name + "BannerBackground"] = new PropertyString(_textboxBackgroundUrl.Text); clonedProperties[Name + "BannerWidth"] = new PropertyString(_textboxWidth.Text); clonedProperties[Name + "BannerHeight"] = new PropertyString(_textboxHeight.Text); */ /* Properties[Name + "BannerBackground"] = new PropertyString(_textboxBackgroundUrl.Text); Properties[Name + "BannerWidth"] = new PropertyString(_textboxWidth.Text); Properties[Name + "BannerHeight"] = new PropertyString(_textboxHeight.Text); SetValue("1"); */ } In all 3 cases, the PropertyDataCollection is updated with 3 new properties, but no data is persisted to the DB. Calling base.ApplyEditChanges throws an NullPointerException. I think it's time for Reflektor :)
#16571
Mar 25, 2008 19:09
Vote:
 
Hi Knut! You are right in the assumption that the page properties are already in writable state whwn in edit mode. I have made an entire sample that you should be able to add to your project and compile to have something to start from. Register this property type in admin. Then add two properties for the page type you want to have the property on. The second one should have the same name as the first one with the suffix "2". The second one should also have "Visible in edit mode" set to false. I'll see if we can add this information in a more detailed form in the sdk or as an article. using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using EPiServer.Web.PropertyControls; using EPiServer.Core; namespace EPiServer.Test { public class MyCustomProperty : PropertyString { public override IPropertyControl CreatePropertyControl() { return new MyCustomPropertyControl(); } } public class MyCustomPropertyControl : PropertyStringControl { private TextBox _input1; public TextBox Input1 { get { return _input1; } set { _input1 = value; } } private TextBox _input2; public TextBox Input2 { get { return _input2; } set { _input2 = value; } } public override void CreateEditControls() { Input1 = new TextBox(); Input1.Text = Properties[Property1Name].Value as string; Controls.Add(Input1); Input2 = new TextBox(); Input2.Text = Properties[Property2Name].Value as string; Controls.Add(Input2); } public override void ApplyEditChanges() { SetValue(Input1.Text, Properties[Property1Name]); SetValue(Input2.Text, Properties[Property2Name]); } protected string Property1Name { get { return Name; } } protected string Property2Name { get { return Name + "2"; } } } }
#16572
Mar 25, 2008 19:09
Vote:
 
Thanks for the feedback! With this example, it seems to work as intended. I assume that it's not possible to add the Properties dynamically. They must be specified in the page before beeing able to add them (and set them to editable = false). That's ok. In the control/property I am working on, I have a GridView where the user can add new rows as needed. The data will be serialized as XML into the property. Now I can have several properties on the page, as you showed in the example, and then serialize the XML into a dedicated property, which will be very helpful. Thanks!
#16573
Mar 25, 2008 19:09
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.