Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more
Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more
Can you give little a bit more details about the actual property which attribute applied to!?
It is actually not a property or well, maybe it is!? :)
I have a plugin for Episerver and in Admin / Config / Plug-in Manager in the Edit plug-in dialog I want to be able to use this property.
It is actually a tab selector property so to speak. The user should connect one or more tabs to my plugin.
Maybe there is a better may to do this? Select one or more tabs use in a plug-in?
Thanks Aria!
I think it is better to have property! If it still doesn't work after that if you can share some of the code and I'm more than happy to take a look :)
Something like:
[PlugInProperty(Description =
"Tabs to select properties from"
, AdminControl =
typeof
(TabSelectorSettingsUi))]
public CheckBoxList SelectedTabs { get; set; }
I'm not sure about backing type (CheckBoxList) ... it could be string and you can store as comma-separated items! Need to try
using System; using System.Web.UI.WebControls; using EPiServer.PlugIn; namespace Episerver75.Settings { [GuiPlugIn(Area = PlugInArea.None, DisplayName = "Settings")] public class MySettings : IMySettings { private static MySettings _instance; [PlugInProperty(Description = "Tabs to select properties from", AdminControl = typeof(TabSelectorSettingsUi))] public string SelectedTabs { get; set; } public MySettings() { PlugInSettings.SettingsChanged += MySettingsSettingsChanged; } private static void MySettingsSettingsChanged(object sender, EventArgs e) { _instance = null; } public static MySettings Instance { get { if (_instance == null) { _instance = new AmestoTranslationSettings(); } PlugInSettings.AutoPopulate(_instance); return _instance; } } } }
using System; using EPiServer.Core.PropertySettings; using EPiServer.Data.Dynamic; namespace Settings.Controls { public class TabSelectorSettings : IPropertySettings { public TabSelectorSettings() { SelectedCategories = string.Empty; } [EPiServerDataMember] public string SelectedCategories { get; set; } public IPropertySettings GetDefaultValues() { return new TabSelectorSettings(); } public IPropertySettings Copy() { var settings = new TabSelectorSettings(); settings.SelectedCategories = this.SelectedCategories; return settings; } public Guid Id { get; set; } } }
using System.Collections.Generic; using System.Linq; using System.Web.UI.WebControls; using EPiServer.Core.PropertySettings; namespace Settings.Controls { public class TabSelectorSettingsUi : PropertySettingsControlBase { private CheckBoxList tabs; protected override void CreateChildControls() { base.CreateChildControls(); tabs = new CheckBoxList(); tabs.Items.Add(new ListItem("Test 0", "0")); tabs.Items.Add(new ListItem("Test 1", "1")); tabs.Items.Add(new ListItem("Test 2", "2")); Controls.Add(tabs); } public override void LoadSettingsUI(IPropertySettings propertySettings) { EnsureChildControls(); var tabSelectorSettings = propertySettings as TabSelectorSettings; if (tabSelectorSettings == null) { return; } var selectedTabs = tabSelectorSettings.SelectedCategories.Split(','); foreach (ListItem tab in tabs.Items) { if(selectedTabs.Contains(tab.Value)) { tab.Selected = true; } } } public override void UpdateSettings(IPropertySettings propertySettings) { EnsureChildControls(); var tabSelectorSettings = propertySettings as TabSelectorSettings; if (tabSelectorSettings == null) { return; } var selectedTabs = new List<string>(); foreach (ListItem tab in tabs.Items) { if (tab.Selected) { selectedTabs.Add(tab.Value); } } tabSelectorSettings.SelectedCategories = string.Join(",", selectedTabs); } } }
So this is the code example for my test with using settings.
And here is the property example
using System; using System.Web.UI.WebControls; using EPiServer.PlugIn; namespace Episerver75.Settings { [GuiPlugIn(Area = PlugInArea.None, DisplayName = "Settings")] public class MySettings : IMySettings { private static MySettings _instance; [PlugInProperty(Description = "Tabs to select properties from", AdminControl = typeof(TabSelectorPropertyControl))] public string SelectedTabs { get; set; } public MySettings() { PlugInSettings.SettingsChanged += MySettingsChanged; } private static void MySettingsSettingsChanged(object sender, EventArgs e) { _instance = null; } public static MySettings Instance { get { if (_instance == null) { _instance = new MySettings(); } PlugInSettings.AutoPopulate(_instance); return _instance; } } } }
using System; using EPiServer.Core; using EPiServer.PlugIn; namespace Settings.Controls { [PropertyDefinitionTypePlugIn] [Serializable] public class TabSelectorProperty : PropertyMultipleValue { public override IPropertyControl CreatePropertyControl() { return new TabSelectorPropertyControl(); } } }
using System.Web.UI.WebControls; using EPiServer.Core; using EPiServer.Web.PropertyControls; namespace Settings.Controls { public class TabSelectorPropertyControl : PropertySelectMultipleControlBase { protected override bool ShouldCreateDefaultControls() { return false; } public PropertyMultipleValue CheckboxListValue { get { return PropertyData as PropertyMultipleValue; } } protected override void SetupEditControls() { SetupDropDownList(); } protected override void CreateChildControls() { this.SetupDropDownList(); } protected virtual void SetupDropDownList() { this.AddItems(); if (CheckboxListValue != null && CheckboxListValue.Value != null) { foreach (var value in CheckboxListValue.ToString().Split(',')) { ListItem li = EditControl.Items.FindByValue(value); if (li != null) li.Selected = true; } } } private void AddItems() { this.EditControl = new CheckBoxList(); this.EditControl.EnableViewState = false; this.ApplyControlAttributes((WebControl)this.EditControl); this.EditControl.RepeatColumns = 3; this.EditControl.Style["display"] = "inline"; EditControl.Items.Add(new ListItem("Test 0", "0")); EditControl.Items.Add(new ListItem("Test 1", "1")); this.Controls.Add(this.EditControl); } } }
Both of my above example gives me:
[NullReferenceException: Object reference not set to an instance of an object.] EPiServer.UI.Admin.PlugInAdminSettings.Save() +1239 EPiServer.UI.Admin.PlugInEdit.Save(Object sender, EventArgs e) +21 EPiServer.UI.WebControls.ToolButton.OnClick(EventArgs e) +125 EPiServer.UI.WebControls.ToolButton.RaisePostBackEvent(String eventArgument) +222 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1734
So I solved it.
The key was to use the AdminControlValue on the PluginProperty definition
[PlugInProperty(LanguagePath = "/Translations/Settings/SelectedTabs", AdminControl = typeof(TabSelectorPropertyControl), AdminControlValue = "CheckboxListValue")]
Make a property CheckboxListValue that gets and sets the value of your property then it works just fine.
/Kristoffer
@Kristoffer: Good one you I just wanted to write down that :D :) but anyway sorry for late response
Hi!
I am trying to have my plugin have a proprty of a checkbox list to save multiple setting values for my plugin.
I have tried a couple of different ways.
[PlugInProperty(Description = "Tabs to select properties from", AdminControl = typeof(TabSelectorSettingsUi))]
Where TabSelectorSettingsUi is inheriting PropertySettingsControlBase.
I have also tried
public class TabSelectorPropertyControl : PropertySelectMultipleControlBase
I can get both of these to generate a checkbox list but when I try to save I get the same error for both versions:
[NullReferenceException: Object reference not set to an instance of an object.] EPiServer.UI.Admin.PlugInAdminSettings.Save() +1239 EPiServer.UI.Admin.PlugInEdit.Save(Object sender, EventArgs e) +21
What did I miss?
Thanks!
/Kristoffer