我正在ASP.NET WebForms中创建一个自定义服务器控件,并希望在我的属性名称中使用连字符,与ASP.NET服务器控件在标记中的操作方式相同。例如,Label控件在标记中具有“字体大小”属性,如下所示:
<asp:Label ID="Label1" Font-Size="small" Text="hi" runat="server" />
我如何做到这一点?
答案 0 :(得分:3)
只需在控件上使用复杂属性:
public class MyControl: WebControl
{
public Test()
{
// Make sure to initialize the complex property or you will get a NRE
// when you try to set the Complex-Bar property in the webpage
Complex = new Complex();
}
public Complex Complex { get; set; }
}
public class Complex
{
public string Bar { get; set; }
}
然后:
<asp:MyControl runat="server" ID="myControl" Complex-Bar="foo bar" />
答案 1 :(得分:1)
我添加了以下内容以使intellisense使用复杂属性:
[Category("Appearance")]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
[PersistenceMode(PersistenceMode.InnerProperty)]