Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more
AI OnAI Off
Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more
I'm an idiot, turns out all I needed to do was to add EnableViewState="true" to the UserControl 🤦♂️
I am creating a UserSettings tab for additional information based on these instructions: https://world.episerver.com/forum/legacy-forums/Episerver-CMS-version-5/Thread-Container/2007/11/EPiServerProfile--user-data/
I am creating the tab as an ascx UserControl, which - I have to admit - I haven't worked with for a long time and don't really remember allt he ins and outs of it.
Everything works as expected, except that a DropDownList that I am displaying is reset before the selected value is saved (epi calls OnLoad when I click on Save in the UI).
Here's some snippets that hopefully shows enough to figure it out:
In the ascx (snippet of dropdown):
The backend code:
[GuiPlugIn(DisplayName = "Additional User Settings", Description = "Additional User Settings", Area = PlugInArea.SidSettingsArea, Url = "~/modules/UserSettings.ascx")] public partial class UserSettings : System.Web.UI.UserControl, IUserSettings, ICustomPlugInLoader { private readonly IDictionary<string, string> markets; public UserSettings() { var CVLService = new CVLService(); markets = CVLService.GetCVL("Market"); } private IDictionary<string, string> createMarketsList() { if (marketList.DataSource == null) { marketList.DataSource = markets; marketList.DataBind(); } return markets; } public bool SaveRequiresUIReload { get; set; } protected override void OnLoad(EventArgs e) { base.OnLoad(e); createMarketsList(); } public void LoadSettings(string userName, EPiServerProfile data) { if (!IsPostBack) { createMarketsList(); firstName.Text = data.FirstName; lastName.Text = data.LastName; avatar.Text = data.GetPropertyValue("Avatar").ToString(); var market = data.GetPropertyValue("Market").ToString(); if (string.IsNullOrWhiteSpace(market) || !markets.ContainsKey(market)) market = "global"; marketList.SelectedValue = market; } } public void SaveSettings(string userName, EPiServerProfile data) { data.FirstName = firstName.Text; data.LastName = lastName.Text; data.SetPropertyValue("Avatar", avatar.Text); data.SetPropertyValue("Market", marketList.SelectedValue); data.Save(); } public PlugInDescriptor[] List() { return new[] { PlugInDescriptor.Load(typeof(UserSettings)) }; } }
The other values works as expected. Is there a solution to this problem?
Peter