2010-03-06 2 views
0

TextControl 또는 RADEditor 컨트롤을 렌더링하는 복합 컨트롤을 만들었습니다.이 컨트롤은 속성 집합에 의존합니다. 두 렌더링 된 컨트롤에는 Text 속성이 있습니다. 문제는 내 웹 페이지에서 Textvalue를 변경할 때 (실행 중일 때) 새로운 Text-value를 설정하지 않고 이전 Textvalue를 대신 설정한다는 것입니다.내 ASP.NET Composite 컨트롤의 텍스트 속성이 텍스트 변경을 설정하지 않습니다.

내가 뭘 잘못하고 있는지 알 수 있습니까?

아래 코드는 복합 컨트롤입니다. 사전

종류에 관해서

using System; 
using System.Collections.Generic; 
using System.ComponentModel; 
using System.Linq; 
using System.Text; 
using System.Web; 
using System.Web.UI; 
using System.Web.UI.WebControls; 
using Telerik.Web.UI; 
using System.Web.UI.HtmlControls; 
using Framework.WebControls; 

namespace Components.Broadcasting.Controls 
{ 

    [DefaultProperty("Text")] 
    [ToolboxData("<{0}:TextControl runat=server></{0}:TextControl>")] 
    public class TextControl : CompositeControl, INamingContainer, IDisposable 
    {  
     //private Control _myControl; 
     private Label _myLabel; 
     private HtmlGenericControl _contentContainer; 
     private HtmlGenericControl _labelBlock; 
     private HtmlGenericControl _inputBlock; 

     public override ControlCollection Controls 
     { 
      get 
      { 
       EnsureChildControls(); 
       return base.Controls; 
      } 
     } 

     [Bindable(true)] 
     [Category("Appearance")] 
     [DefaultValue("")] 
     [Localizable(true)] 
     public string Text 
     { 
      get 
      {     
       String s = (String)ViewState["Text"]; 
       return ((s == null) ? String.Empty : s); 
      } 

      set 
      {     
       ViewState["Text"] = value; 
      } 
     } 

     [Bindable(true)] 
     [Category("Campagne Broadcasting")] 
     [DefaultValue("Naam label")] 
     [Description("Label horende bij het contenttype")]   
     public string Label 
     { 
      get 
      { 
       String s = (String)ViewState["label"]; 
       return ((s == null) ? String.Empty : s); 
      } 

      set 
      { 
       ViewState["label"] = value; 
      } 
     } 

     [Bindable(true)] 
     [Category("Campagne Broadcasting")] 
     [DefaultValue(XMLElementType.Heading)] 
     [Description("Nog in te vullen")] 
     public XMLElementType XMLElementType 
     { 
      get 
      { 
       if (ViewState["textContentType"] == null) return XMLElementType.Heading; 
       return (XMLElementType)ViewState["textContentType"]; 
      } 
      set 
      { 
       ViewState["textContentType"] = value; 
      } 
     } 

     [Bindable(true)] 
     [Category("Campagne Broadcasting")] 
     [DefaultValue("0")] 
     [Description("Layoutposition of the contentitem")] 
     public int ContentPosition 
     { 
      get 
      { 
       if (ViewState["contentPosition"] == null) return 0; 
       return (int)ViewState["contentPosition"]; 
      } 
      set 
      { 
       ViewState["textContentType"] = value; 
      } 
     } 

     [Bindable(true)] 
     [Category("Campagne Broadcasting")] 
     [DefaultValue("0")] 
     [Description("Layoutposition of the contentitem")] 
     public XmlOutputGroup XMLOutputGroup 
     { 
      get 
      { 
       if (ViewState["xmlOutputGroup"] == null) return 0; 
       return (XmlOutputGroup)ViewState["xmlOutputGroup"]; 
      } 
      set 
      { 
       ViewState["xmlOutputGroup"] = value; 
      } 
     } 

     protected override void RecreateChildControls() 
     { 
      EnsureChildControls(); 
     } 

     protected override void CreateChildControls() 
     { 
      Controls.Clear(); 

      string containerClass = "contentContainer"; 
      string labelBlock = "labelBlock"; 
      string inputBlock = "inputBlock"; 

      _myLabel = new Label(); 
      _myLabel.Text = Label; 
      _contentContainer = new HtmlGenericControl("div"); 
      _contentContainer.Attributes["class"] = containerClass; 

      _labelBlock = new HtmlGenericControl("div"); 
      _labelBlock.Attributes["class"] = labelBlock; 
      _inputBlock = new HtmlGenericControl("div"); 
      _inputBlock.Attributes["class"] = inputBlock; 

      _contentContainer = new HtmlGenericControl("div"); 
      _contentContainer.Attributes["class"] = containerClass; 
      _labelBlock.Controls.Add(_myLabel); 

      if (XMLElementType == XMLElementType.Heading) 
      { 
       TextBox _myControl = new TextBox(); 
       _myControl.Text = this.Text; 
       _inputBlock.Controls.Add(_myControl); 
      } 
      else if (XMLElementType == XMLElementType.Content) 
      { 
       RadEditor _myControl = new RadEditor(); 
       _myControl.Content = this.Text; 
       _inputBlock.Controls.Add(_myControl);     

      } 
      else if (XMLElementType == XMLElementType.SlideTypeName) 
      { 
       TextBox _myControl = new TextBox(); 
       _myControl.Text = this.Text; 
       _inputBlock.Controls.Add(_myControl); 
      } 
      else if (XMLElementType == XMLElementType.Image) 
      { 
       ImageUploader _myControl = new ImageUploader();     
       _inputBlock.Controls.Add(_myControl); 
      } 

      _contentContainer.Controls.Add(_labelBlock); 
      _contentContainer.Controls.Add(_inputBlock); 

      this.Controls.Add(_contentContainer);   
     } 

     protected override void RenderContents(HtmlTextWriter output) 
     {   
      _contentContainer.RenderControl(output);    
     } 
    } 
} 

감사합니다, 패트릭

답변

0

에만을 CreateChildControls에서 그들을 사용하고 있지만, 같은 레이블, 텍스트 등의 속성을 노출하는 - 너무 일찍 페이지 라이프 사이클이다. 이 문제를 해결하는 가장 쉬운 방법은 Label 속성에 대한 아래 예제와 같이 속성을 자식 컨트롤에 위임하는 것입니다. 마찬가지로 Text 속성을 처리 할 수 ​​있습니다.

또는 RenderContents 재정의에서 하위 컨트롤의 속성을 설정할 수 있지만 다소 복잡합니다.

public string Label 
{ 
    get 
    { 
     EnsureChildControls(); 
     return _myLabel.Text; 
    } 

    set 
    { 
     EnsureChildControls(); 
     _myLabel.Text = value; 
    } 
} 
관련 문제