C# ASP.NET 4.0中自定义控件内的复杂类型
如何在自定义控件内设置复杂属性,我已尝试了以下方法。问题是我无法访问自定义控件类中的复杂属性 自定义控制代码示例:C# ASP.NET 4.0中自定义控件内的复杂类型,c#,asp.net,properties,custom-controls,C#,Asp.net,Properties,Custom Controls,如何在自定义控件内设置复杂属性,我已尝试了以下方法。问题是我无法访问自定义控件类中的复杂属性 自定义控制代码示例: public class MyCustomControl : Control, IStylesheet { [ Bindable(true), Category("Appearance"), DefaultValue(""), Description("FullName"
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标记
<Namespace:MyCustomControl runat="server"">
<MyFullName Firstname="abc" Lastname="def" />
</Namespace:MyCustomControl>
我假设您无法从自定义控件的呈现方法内部获取标记中设置的FirstName/lastname属性的值
试试这篇文章。下面是适用于您的情况的文章摘录
MyFullName属性和MyFullName类的属性需要设计时属性才能在控件的标记中启用持久性,如下例所示:
<aspSample:MyCustomControl >
<MyFullName FirstName="Jody" LastName="Foster" />
</aspSample:MyCustomControl>
MyCustomControl控件将其简单属性存储在ViewState字典中。但是,MyCustomControl控件必须对FullName属性实施自定义状态管理,以跨回发管理属性的状态。您所说的“我无法访问自定义控件类中的复杂属性”是什么意思?为什么你不能这样做。我的全名??我有一个定义了[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)、MergableProperty(false)、PersistenceMode(PersistenceMode.InnerProperty)]的属性,我可以很好地访问它。。。