2

Need to add a unique ID property in a composer tab, what's the best way of doing this and here's my attempt:

[PageTypeProperty(
           EditCaption = "UniqueID",
           HelpText = "UniqueID",
           Type = typeof(PropertyString),
            //DisplayInEditMode=false,
           Tab = typeof(ComposerTab))]
        public virtual Guid UniqueID
        {
            get { return UniqueID; }
            set { UniqueID = System.Guid.NewGuid(); }
        }

Intended behaviour: each time a new textbox is added on the page, it should be assigned a unique ID.

Problem with this piece of code is I don't see a unique ID entered in the text box when in Composer - Edit Mode (when I check the properties of this content block)

Please comment on correct way to set this GUID property and where. Thanks!

Later edit:

http://tedgustaf.com/blog/2011/9/create-episerver-composer-function-with-page-type-builder/ This example describes my approach

Block.cs

namespace MyProject.ComposerFunctions
{
    [PageType("70421202Efdghajkfgkjd43535",
    Name = "Block",
    Description = "Block",
    Filename = "Block.ascx")]
    public class Block : BaseComposerFunctionData
    {
        [PageTypeProperty(
           EditCaption = "UniqueID",
           HelpText = "UniqueID",
           Type = typeof(PropertyString),
            //DisplayInEditMode=false,
           Tab = typeof(ComposerTab))]
        public virtual Guid UniqueID
        {
            get { return UniqueID; }
            set { UniqueID = System.Guid.NewGuid(); }
        }

    }
}

Block.ascx

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="Block.ascx.cs" Inherits="MyProject.ComposerControls.Block" %>

Block.ascx.cs

namespace MyProject.ComposerControls
{
    public partial class Block : Dropit.Extension.Core.BaseContentFunction
    {

        protected override void OnLoad(EventArgs e)
        {
            if (!IsPostBack)
            {

                this.DataBind();

            }
        }
    }
}

BaseContentFunction is derived from UserControl, IPageSource, IFunctionSource BaseComposerFunctionData is derived from TypedPageData

dear1
  • 103
  • 11

1 Answers1

1

I'm not quit sure if this will work, but could you try the following in your Block.cs?

[PageTypeProperty(
           EditCaption = "UniqueID",
           HelpText = "UniqueID",
           Type = typeof(PropertyString),
           //DisplayInEditMode=false,
           Tab = typeof(ComposerTab))]
        public virtual Guid UniqueID { get; set; }

        public override void SetDefaultValues(ContentType contentType)
        {
            UniqueID = System.Guid.NewGuid();
        }
andreasnico
  • 1,478
  • 14
  • 23
  • Thank you andreasnico! Unfortunately I get `Error 15 'MyProject.Templates.ComposerFunctions.BCATextBlock.SetDefaultValues(System.Net.Mime.ContentType)': no suitable method found to override ` on the SetDefaultValues line – dear1 Apr 11 '16 at 08:58
  • ah, this was first implemented in episerver 7+. Sorry :( – andreasnico Apr 11 '16 at 10:10