문제

중첩 서버 컨트롤이 포함 된 서버 컨트롤이 있습니다.

<uc1:ArticleControl runat="server">
     <HeadLine></HeadLine>
     <Blurb></Blurb>
     <Body></Body>
</uc1:ArticleControl>

암호:

[ToolboxData("<{0}:ArticleControl runat=server></{0}:ArticleControl>")]
[ParseChildren(ChildrenAsProperties = true)]
public class ArticleControl : WebControl
{

    [PersistenceMode(PersistenceMode.InnerProperty)]
    public HeadLineControl HeadLine 
    {
        get;
        set;
    }

    [PersistenceMode(PersistenceMode.InnerProperty)]
    public BlurbControl Blurb
    {
        get;
        set;
    }

    [PersistenceMode(PersistenceMode.InnerProperty)]
    public BodyControl Body
    {
        get;
        set;
    }
}

중첩 된 제어 정의 (모든 중첩 컨트롤에 적용) :

 public class HeadLineControl : ControlBase
     {
          public HeadLineControl() : base() { }
          public HeadLineControl(Article article) : base(article) { }

기본 클래스 정의

public abstract class ControlBase : Control
{
     protected Article article;

     protected ControlBase() { }
     protected ControlBase(Article article)
     {
          this.article = article;
     }

ArticleControl은 중첩 된 컨트롤에서 지정된 기사의 개별 부분에 대한 글을 쓸 책임이 있습니다.

내 문제는 ArticleControl이 생성되면 System.web.ui.control class : Control Class : Control Class : Control Class : Control Class : Control Control의 인스턴스가 .NET Framework에 의해 생성된다는 것입니다.

namespace System.Web.UI
{

public class Control : IComponent, IDisposable, IParserAccessor, IUrlResolutionService, IDataBindingsAccessor, IControlBuilderAccessor, IControlDesignerAccessor, IExpressionsAccessor
    {
        // Summary:
        //     Initializes a new instance of the System.Web.UI.Control class.
        public Control();

기본 .NET 정의 대조 업체의 대구에서 제어 기본 클래스 생성자를 호출하려면 .NET의 기본 동작을 호출하거나 재정의해야합니다. 요컨대, 새로운 인스턴스의 HeadlineControl이 생성되면 ControlBase(Article article) 헌자.

이것이 가능하고 가능하다면 어떻게이를 달성합니까?

도움이 되었습니까?

해결책

그 동안 해결 방법 으로이 작업을 수행했지만 더 나은 방법이 있어야합니까?

[PersistenceMode(PersistenceMode.InnerProperty)]
 public HeadLineControl HeadLine 
 {
      get { return null; }
      set 
      {
          this.Controls.Add(new HeadLineControl(articlePage.Article)();
      }
 }
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top