1

正直なところ、データバインディングがこれを達成するための正しい手法であるかどうかはわかりません。

基本的に私がやろうとしているのは、現在のページから Web ユーザー コントロールにオブジェクトを渡すことです (コードは簡略化されています)。

ExamplePage.aspx

<div>
    <EC:AttachmentsView ID="AttachmentsView1" Attachments=<%# this.PageAttachments %> runat="server" />
</div>

ExamplePage.aspx.cs

public partial class ExamplePage : ProductBase
{
    private LinkItemCollection _pageAttachments;
    public LinkItemCollection PageAttachments
    {
        get { return _pageAttachments; }
    }

    public ExamplePage()
    {
        this.Load += new EventHandler(this.Page_Load);
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        // Accessing and assigning attachments (EPiServer way)
        _pageAttachments = CurrentPage["Attachments"] as LinkItemCollection ?? new LinkItemCollection();
    }
}

Attachment添付ビュー コントロールには、およびプロパティのセッターとゲッターがありLabelます。

添付ファイルView.ascx.cs

namespace Example.Controls
{
    [ParseChildren(false)]
    public partial class AttachmentsView : EPiServer.UserControlBase
    {
        private string _label;
        public string Label
        {
            get { return _label; }
            set { _label = value; }
        }

        private LinkItemCollection _attachments;
        public LinkItemCollection Attachments
        {
            get { return _attachments; }
            set { _attachments = value; }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (_attachments == null)
            {
                _attachments = CurrentPage["DefaultAttachments"] as LinkItemCollection ?? new LinkItemCollection();
            }
        }
    }
}

私は、ExamplePage からのページ添付ファイルが AttachmentsView コントロールに渡されることを期待する段階にいますが、_attachments プロパティは null です。

私がやろうとしていることは可能ですか?データバインディングは正しいテクニックですか?もしそうなら、恐ろしいMSDNのドキュメントよりも簡単に概念を説明する資料を知っている人はいますか?

コントロールをプログラムでレンダリングすることでおそらくこれを達成できることはわかっていますが、最初にこの方法を試してみたいと思います。

4

0 に答える 0