C# 是否在创建控件时将属性指定给控件?
只是想知道是否可以不拆分以下步骤C# 是否在创建控件时将属性指定给控件?,c#,asp.net,controls,C#,Asp.net,Controls,只是想知道是否可以不拆分以下步骤 Button b = new Button() { // You can access Attributes here, but only get, not set. ID = "btnExample", Text = "Click Me" }; b.Attributes.Add("onclick", "alert('hello, world')"); 提前感谢。您可以从按钮驱动并将其添加到构造函数: class MyButton:
Button b = new Button()
{
// You can access Attributes here, but only get, not set.
ID = "btnExample",
Text = "Click Me"
};
b.Attributes.Add("onclick", "alert('hello, world')");
提前感谢。您可以从按钮驱动并将其添加到构造函数:
class MyButton: Button
{
MyButton(MyAttributes atr)
{
for each (elm in atr)
{
base.Attributes.Add(elm.Key, elm.Value);
}
}
}