2

需要在作曲家选项卡中添加一个唯一的 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 - 编辑模式下没有看到在文本框中输入的唯一 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、IFunctionSource BaseComposerFunctionData 派生自 TypedPageData

4

1 回答 1

1

我不确定这是否可行,但是您可以在 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();
        }
于 2016-04-07T07:09:10.750 回答