Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/34.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 是否在创建控件时将属性指定给控件?_C#_Asp.net_Controls - Fatal编程技术网

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);
       }
    }
}