2011-07-22 10 views
0

カスタムコントロール内で複雑なプロパティを設定する方法は次のとおりです。問題は、カスタムコントロールクラス内の複雑なプロパティにアクセスできないことです。ASP.NET 4.0のカスタムコントロール内の複合型

例カスタム制御コード:私はあなたからマークアップに設定されている姓/姓プロパティの値を取得することができないと仮定してい

<Namespace:MyCustomControl runat="server""> 
    <MyFullName Firstname="abc" Lastname="def" /> 
</Namespace:MyCustomControl> 
+1

「カスタムコントロールクラス内の複合プロパティにアクセスできません」という意味はどうですか?なぜあなたはこれをやり遂げることができないのですか?私は、[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)、MergableProperty(false)、PersistenceMode(PersistenceMode.InnerProperty)]というプロパティを定義しています。 –

答えて

1

public class MyCustomControl : Control, IStylesheet 
{ 
     [ 
      Bindable(true), 
      Category("Appearance"), 
      DefaultValue(""), 
      Description("FullName"), 
      DesignerSerializationVisibility(DesignerSerializationVisibility.Content), 
      PersistenceMode(PersistenceMode.InnerProperty), 
     ] 
     public FullName MyFullName {get; set;} 

     protected override void Render(HtmlTextWriter writer) 
     { 
      // I want to access MyFullName from .aspx here 
     } 
} 

public class FullName 
{ 
    public string Firstname {get; set;} 
    public string Lastname {get; set;} 
} 

.aspxのマークアップカスタムコントロールのレンダリングメソッドの内部

お試しthis記事です。あなたの状況に適用された記事の抜粋は以下の通りです。

MyFullNameプロパティとMyFullNameクラスのプロパティは、デザイン時には、必要が次の例に示すように、コントロールのタグ内持続性を有効にするには、属性:

<aspSample:MyCustomControl > 
     <MyFullName FirstName="Jody" LastName="Foster" /> 
    </aspSample:MyCustomControl> 

MyCustomControl制御店舗での単純なプロパティをViewState辞書。ただし、MyCustomControlコントロールは、FullNameプロパティのカスタム状態管理を実装して、ポストバック間でプロパティの状態を管理する必要があります。

関連する問題