Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Ferdy Hoefakker 214 posts 248 karma points
    Jul 18, 2011 @ 14:11
    Ferdy Hoefakker
    0

    Saving member properties

    Hey all,

    I have been trying to make a page to edit member properties. So, I got all the properties and bound them to a repeater:

    umbraco.cms.businesslogic.property.Properties props = member.GenericProperties;
                    if (props != null)
                    {
                        rptProperties.DataSource = props.ToList();
                        rptProperties.DataBind();
                    }

    Inside the repeater item template, I placed an umbraco propertypanel which I gave an ID and left it's contents blank. Then, in the ItemDatabound function, I insert the properties editor control.

    protected void rptPropertyOverzicht_ItemDataBound(object sender, RepeaterItemEventArgs e)
            {
                if (e.Item.DataItem != null)
                {
                    PropertyPanel panel = e.Item.FindControl("propPanel") as PropertyPanel;
                    Property prop = (Property)e.Item.DataItem;
                    panel.Text = prop.PropertyType.Name;

                    Control ctrl = (Control)prop.PropertyType.GetEditControl(prop.Value, false).DataEditor.Editor;
                    ctrl.ID = "prop_" + prop.PropertyType.Name;
                    panel.Controls.Add(ctrl);
                }
            }

    Sofar, this works great. The problem comes when I try to save any changes I made. I have tried dozens of things, but I just can't retrieve the value of the controls and save them.

    What am I missing here?

    -Ferdy

  • Ferdy Hoefakker 214 posts 248 karma points
    Jul 18, 2011 @ 16:52
    Ferdy Hoefakker
    0

    I am currently managing the saving of the properties, but it seems a really awkward way of getting it done. It works, but I would need to add a case to my switch statement for each and every new propertytype. It seems to me it should be much easier to get it done as the both the default document and member pages allow custom properties and are able to save them.

    I checked the umbraco 4.5.2 source, but I just can't locate the code that handles the list of custom properties on a memberpage in the backend.

    PropertyPanel panel = item.FindControl("propPanel") as PropertyPanel;
    Property prop = props.Where(p => p.PropertyType == (PropertyType.GetAll().Where(x => x.Name == panel.Text).First())).First();
    var ctrl = panel.FindControl("prop_" + prop.PropertyType.Name);
    switch (ctrl.GetType().ToString())
    {
                            case "umbraco.editorControls.yesNo":
                                CheckBox chk = (CheckBox)panel.FindControl("prop_" + prop.PropertyType.Name.ToString()) as CheckBox;
                                member.getProperty(prop.PropertyType).Value = chk.Checked;
                                break;
                            case "umbraco.editorControls.numberField":
                                TextBox tb = (TextBox)panel.FindControl("prop_" + prop.PropertyType.Name) as TextBox;
                                member.getProperty(prop.PropertyType).Value = tb.Text.ToString();
                                break;
                            case "umbraco.editorControls.textfield.TextFieldEditor":
                                TextBox tb2 = (TextBox)panel.FindControl("prop_" + prop.PropertyType.Name) as TextBox;
                                member.getProperty(prop.PropertyType).Value = tb2.Text.ToString();
                                break;
    }
  • Ferdy Hoefakker 214 posts 248 karma points
    Aug 15, 2011 @ 09:07
    Ferdy Hoefakker
    0

    If anyone has a more elegant way of doing this, I'd still appreciate hearing it.

    -Ferdy

Please Sign in or register to post replies

Write your reply to:

Draft