1-888-365-2779
+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Control designer for wrapped Generic Content

Control designer for wrapped Generic Content

4 posts, 0 answered
  1. Matthew Hensley
    Matthew Hensley avatar
    3 posts
    Registered:
    26 Oct 2009
    28 Apr 2010
    Link to this post
    This example on wrapping a Generic Content item in a UserControl is simple and easy to get working. I have added a property named "Title" to the code behind and a Literal to the ascx and everything works as expected.

    Replacing the GenericContentDesigner with a custom designer that includes the title has proven difficult. Are there any examples available for Sitefinity 3.7 on how to extend the GenericContentDesigner and add a custom field?
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    29 Apr 2010
    Link to this post
    Hello Matthew Hensley,

    You could take a look at How to wrap a Generic Content control

    Greetings,
    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. Matthew Hensley
    Matthew Hensley avatar
    3 posts
    Registered:
    26 Oct 2009
    29 Apr 2010
    Link to this post
    I have followed basically the same example: Wrapping GenericContent in a UserControl

    My question is how to make a appropriate  designer that lets me edit both the content and the title.
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    29 Apr 2010
    Link to this post
    Hello Matthew Hensley,

    You have to expose TexBox control in the designer template of GenericContent control.
    In the designer you have to get the content item and its Metakey Name or a property you want to show

    protected override void InitializeControls(System.Web.UI.Control viewContainer)
        {
            base.InitializeControls(viewContainer);
     
            if (this.DesignedControl.SharedContent != null)
            {
                TextBoxTitle.Text = ((CustomGenericContent)DesignedControl).SharedContent.GetMetaData("Title").ToString();
     
            }
          
     
        }
     
     
     
        // the code executes when you click "I'm done "
        public override void OnSaving()
        {
            base.OnSaving();      
            ((CustomGenericContent)DesignedControl).TitlePersistanceProperty.Text = TextBoxTitle.Text;
     
             
            if (DesignedControl.SharedContent != null)
            {
                ContentManager manager = this.Manager;
     
                IContent content = manager.GetStagedContent(this.DesignedControl.ContentID);
                if (content != null)
                {
                    content.SetMetaData("Title", TextBoxTitle.Text);
                    manager.SaveContent(content);
                }
            }
     
     
        }

    Inside CusstomGenericContent you should have a public property to persist the Title of the current item

    protected override void CreateChildControls()
           {
               base.CreateChildControls();
               if (this.SharedContent != null)
               {
                   this.TitlePersistanceProperty.Text = this.SharedContent.GetMetaData("Title").ToString();
               }
               else
               {

               }
           }


    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.
Register for webinar
4 posts, 0 answered