More in this section

Forums / Developing with Sitefinity / Complex control properties persist for admin, but not for public

Complex control properties persist for admin, but not for public

6 posts, 1 answered
  1. bemara57
    bemara57 avatar
    135 posts
    Registered:
    27 Mar 2008
    21 Feb 2010
    Link to this post
    I have a control in my template that is exposed for the admin to change from the designer. The "Edit" button shows up for the template's control and am able to edit the Width (for example) and save. I save and go back to the admin designer and see that the width is persisted and indeed the Width value is still there.

    The problem is on the public side. The Width is blank even though it shows up in admin.

    Here's what I did- I placed a label control in my ascx template:

    <asp:Label ID="lblTitle" runat="server" />

    Then in my SimpleControl, I set up the layout template paths and tie this control to a property like this:

    public Label lblTitle
    {
        get
        {
            return base.Container.GetControl<Label>("lblTitle", true);
        }
    }

    On the public side, when I put a breakpoint at that property control, the label's width property I saved in the admin designer is blank, and what's strange is that the Width value even show up when I go back to the designer indicating it is persisted in the system somewhere. The public side doesn't get this value tho. The Width property is blank in the public side. Is there something I am missing?
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    21 Feb 2010
    Link to this post
    Hi bemara57,

    You should have a property in your custom control which actually gets the value from the control designer. Then you need to get the value of this property and display it.

    sample code

    [ControlDesignerAttribute("SampleControlDesigner, App_Code")]
    public class SampleControl: SimpleControl
    {
     
        public SampleControl()
        {
        }
     
        public string MyProperty
        {
            get
            {
                object obj = this.ViewState["MyProperty"];
                if (obj != null)
                    return (string)obj;
                return "someValue";
     
            }
            set
            {
                this.ViewState["MyProperty"] = value;
            }
        }
     
        protected override void CreateChildControls()
        {
     
          
                Label lb1 = new Label();
                lb1.Text = MyProperty.ToString();
                Controls.Add(lb1);
     
            }
        }
    }


    Kind regards,
    Ivan Dimitrov
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  3. bemara57
    bemara57 avatar
    135 posts
    Registered:
    27 Mar 2008
    21 Feb 2010
    Link to this post
    But in this case you are no longer exposing the complex properties of the control for the designer (I don't want to have to manually create a property to each property of the complex control). What if I wanted to expose the properties of a RadRotator? Currently I am doing this:

    public RadRotator rotControl
    {
        get
        {
            return base.Container.GetControl<RadRotator>("rotControl", true);
        }
    }

    But after modifying all the properties in the control designer (such as ItemWidth), they persist in admin. However, in the public side, these properties of the RadRotator I set in the control designer disappear.

    For example, I set ItemWidth to 150px in the control designer and it persists even when I exit and come back. Though when running in the public side, the ItemWidth is empty.
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    21 Feb 2010
    Link to this post
    Hi bemara57,

    The ControlDesigner is used only for the backend when you open a control for editing. The idea of the ContentDesigner is to expose control properties in friendly way, not to manipulate properties on the public side.

    Sincerely yours,
    Ivan Dimitrov
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  5. bemara57
    bemara57 avatar
    135 posts
    Registered:
    27 Mar 2008
    21 Feb 2010
    Link to this post
    What a bummer. I don't see the point then. If they are persisted only for control designer, how do I extract these values so I can manually map these to my control for rendering for the public side?

    If this is not possible, then I really DO have to recreate all the properties of the complex control just so the admin's values get pushed onto the public rendering.
  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    21 Feb 2010
    Link to this post
    Hi bemara57,

    You should have a property in your custom control which actually gets the value from the control designer. Then you need to get the value of this property and display it.

    1. go back and see the previous post with the sample

    2. Here is how to set the property for the designer to the property of the control

    public override void OnSaving()
       {
     
           base.OnSaving();
           ((Samplecontrol)DesignedControl).MyProperty = rotControl.Width;
       }



    Best wishes,
    Ivan Dimitrov
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
    Answered
Register for webinar
6 posts, 1 answered