向Episerver Composer块添加唯一的id属性



需要在composer选项卡中添加一个唯一的ID属性,最好的方法是什么,下面是我的尝试:

[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(); }
        }

预期行为:每次在页面上添加新的文本框时,都应该为其分配一个唯一的ID。

这段代码的问题是,在Composer-Edit模式下(当我检查这个内容块的属性时)时,我没有看到文本框中输入唯一的ID

请评论设置此GUID属性的正确方式和位置。谢谢

后期编辑:

http://tedgustaf.com/blog/2011/9/create-episerver-composer-function-with-page-type-builder/这个例子描述了我的方法

阻止.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(); }
        }
    }
}

区块.ascx

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="Block.ascx.cs" Inherits="MyProject.ComposerControls.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派生自UserControl、IPageSource、IFunctionSourceBaseComposerFunctionData源自TypedPageData

我不确定这是否可行,但你能在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();
        }

相关内容

  • 没有找到相关文章

最新更新