Custom extranet attributes

Vote:
 
Hi, I'm trying to get the custom extranet user attributes to work. The code below seems to be able to show saved data but I don't seem to get this function to save the right data - what is it that I have forgotten to put in this code? Any help appreciated... Regards, Tony H [EPiServer.PlugIn.GuiPlugIn(DisplayName="More...", Description="More attributes for Extranetusers", Area=PlugInArea.SidSettingsArea, Url="~/CustomUserAttributes.ascx")] public class CustomUserAttributes : System.Web.UI.UserControl, ISidSettings { protected TextBox test; private void Page_Load(object sender, System.EventArgs e) { if(!IsPostBack) { DataBind(); } } public void LoadSettings(Sid sid,PersonalizedData data) { if(data["TestAttribute"] != null) test.Text = data["TestAttribute"].ToString(); else test.Text = ""; // Empty } public void SaveSettings(Sid sid,PersonalizedData data) { data["TestAttribute"] = test.Text; data.Save(); } ...
#12678
Jun 19, 2006 15:37
Vote:
 
Here's the code for the aspx-file. <%@ Control Language="c#" AutoEventWireup="false" Codebehind="CustomUserAttributes.ascx.cs" Inherits="development.CustomUserAttributes" TargetSchema="http://schemas.microsoft.com/intellisense/ie5"%> Ett test!!

Funkar?
#14728
Jun 19, 2006 15:41
Vote:
 
Hi again, The problems seems to be in the way that I'm trying to save threw SaveSettings function. I've tested setting a static string in this function which made it work (could now see it in admin). Am I using the TextBox the wrong way? Regards, Tony H
#14729
Jun 19, 2006 21:26
Vote:
 
The Save is supposed to be done for you, all you should be doing in your SaveSettings method is to set the values on the PersonalizedData object.
#14730
Jun 20, 2006 7:11
Vote:
 
Tried to remove Save() but this didn't help. It seems like there could be something wrong with my aspx-file, because the TextBox named Test doesn't seem to collect the value posted. Do I need some more attributes in my aspx file to get this to work? Or am I retrieving the posted parameters the wrong way? Regards, Tony H
#14731
Jun 20, 2006 17:29
Vote:
 
Someone must have added some custom attributes/properties to their users? Isn't there anyone who has some code strip which works? Code and codebehind...
#14732
Jun 27, 2006 20:20
Vote:
 
Hello Tony. Here is the an explanation to your problem. First, there is a difference if you do this in admin mode and editmode. I'll take admin mode first. The tip in adminmode is to skip the LoadSettings if there is a postback. This is because the LoadSetting is executed before the SaveSettings, so you will never update the personalized value. public void LoadSettings(EPiServer.DataAbstraction.Sid sid, EPiServer.Personalization.PersonalizedData data) { if (IsPostBack) return; if (data["MySetting"] != null) { txtSidSetting.Text = data["MySetting"].ToString(); } } public void SaveSettings(EPiServer.DataAbstraction.Sid sid, EPiServer.Personalization.PersonalizedData data) { data["MySetting"] = txtSidSetting.Text; } So to Editmode, which is a little more tricy. The tricky part is that when you click My Settings and when you click on Save a postback is executed. One time you need the value, the other time, you don't want the value. This is one way to do the logic. I'll ask ElektroPost if there is a better way. public void LoadSettings(EPiServer.DataAbstraction.Sid sid, EPiServer.Personalization.PersonalizedData data) { if (txtSidSetting.Text.Length == 0 ) { txtSidSetting.Text = data["MySetting"].ToString(); } } public void SaveSettings(EPiServer.DataAbstraction.Sid sid, EPiServer.Personalization.PersonalizedData data) { data["MySetting"] = txtSidSetting.Text; } /Øyvind
#14733
Jun 28, 2006 15:53
Vote:
 
Thanks! I've just solved it this way by try and fail ;) It seems to work and it looks alot like your admin code. public void LoadSettings(Sid sid,PersonalizedData data) { if(!IsPostBack) { if(data["TestAttribute"] != null) test.Text = data["TestAttribute"].ToString(); } } public void SaveSettings(Sid sid,PersonalizedData data) { data["TestAttribute"] = test.Text; } If my code starts to fail me I'll use yours... Best regards, Tony H
#14734
Jun 28, 2006 16:03
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.