Copied to clipboard

Flag this post as spam?

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


  • João Pereira 41 posts 64 karma points
    Oct 21, 2010 @ 01:05
    João Pereira
    0

    Save member in Admin UI clears all properties values

    Hi there,

     

    I created custom usercontrols (ascx) and added them as DataTypes so I could use them as properties in the Member Profile.

    Everything works fine when the user registers or edits his profile in the page I built for that purpose, but when I save their profile in the Admin UI, when trying to add a new role to a specific user, all the profile properties are overwritten with empty values.

    The controls are simply, except for one that uploads a photo using ajax without postback, but that's not the problem.

     

    I really need the ability to add and remove roles to users, without deleting their profile properies...

    I'm I doing something wrong?

     

    Here's the code for one of the DataTypes I created. It's a dropdownlist that shows a textbox when the user selects the Other option. You can imagine the ascx... :)

    Do I need to add any special method for the Admin UI editing?

    
    
    

            public string umbracoValue;

            protected void Page_Load(object sender, EventArgs e)

            {

                if (Page.IsPostBack)

                {

                    if (!String.IsNullOrEmpty(ddlOption.SelectedValue))

                    {

                        umbracoValue = ddlOption.SelectedValue;

                        if (ddlOption.SelectedValue == "Outro")

                            umbracoValue += "%" + txtOther.Text;

                    }

                }        

            }

            public object value

            {

                get { return umbracoValue; }

                set

                {

                    if (value != null)

                    {

                        string[] val = value.ToString().Split('%');

                        if (val.Length > 1)

                        {

                            umbracoValue = value.ToString();

                            ddlOption.SelectedValue = val[0];

                            txtOther.Text = val[1];

                            divOther.Style.Remove("display");

                        }

                        else

                        {

                            umbracoValue = value.ToString();

                            ddlOption.SelectedValue = value.ToString();

                        }

                    }

                    else { umbracoValue = String.Empty; }

                }

            }

  • Richard Soeteman 4049 posts 12922 karma points MVP 2x
    Oct 21, 2010 @ 08:40
    Richard Soeteman
    0

    What happens when you set a Breakpoint on value property during load and save, I guess something is wrong in there. Again attach a debugger and step throuh the code.

    Cheers,

    Richard

  • João Pereira 41 posts 64 karma points
    Oct 21, 2010 @ 19:28
    João Pereira
    0

    Hi Richard, thanks for your answer and help!

     

    I debugged one of the controls and, when loading, everything works as expected: the property set is activated, and the value is set in ddlOption and rendered as supposed! (it hits the page load method after setting the property value)

    When saving, the page load runs before the get of the property, and the value of the ddlOption returns empty.

    In saving, the  if (Page.IsPostBack) was false and it was never executed, but that's not the problem, because the ddlOption returns it value as an empty string...

    It renders correctly, but when saving the ddl is empty. This remind me a little bit of DNN where the page load cycle overrides all properties and we need to manually create a "ViewState" to save all controls state...

    Do I need to do something like that or there is an easier way?

    Thanks again!

     

  • Richard Soeteman 4049 posts 12922 karma points MVP 2x
    Oct 21, 2010 @ 20:23
    Richard Soeteman
    0

    Oh now I see,

    What you should do is move the logic you have in the Page_Load event to either the getter of the Value property, or create a seperate method and call that in the getter of the value property. If you are doing stuff in the page_load it could be that in a later stage the viewstate is restored (not related to Umbraco or dnn it's just how asp.net works) then all kind of weird things can occur for example index_changed doesn't fire because for asp.net it seems nothing changed etc..

    Cheers,

    Richard

  • João Pereira 41 posts 64 karma points
    Oct 21, 2010 @ 20:35
    João Pereira
    0

    Geeeeez thanks!

     

    I got it working now!

    There's no need to have nothing in the PageLoad... Umbraco automatically get's the property value and we can bind it to the ddl inside...

    All the examples I found (like this http://forum.umbraco.org/yaf_postst5322_custom-data-type.aspx) always bind the value to the control in the page load... And it works with custom pages to manage those properties but not in the Umbraco Admin UI...

     

    Once again thanks a lot! ;)

     

    Oh! Just one more thing... Can I bother you to help me find the answer for my last post in this thread? I bet it's just one more little thing... :/

    http://our.umbraco.org/forum/ourumb-dev-forum/bugs/13287-Umbraco-Admin-UI-not-showing-Tree-Nodes-thumbnail

Please Sign in or register to post replies

Write your reply to:

Draft