private void Button1_Click(object sender, EventArgs e) { string name = (sender as Button).Name; // do something with name. }
服务器端的控件没有Name属性 只有ID
可以设置一个label 初始的时候不可见 当触发click事件的时候是这个label可见 同时将命令按钮的name属性给了label的caption 这里有一个按钮 name 属性为hello Private Sub Form_Load() hello.Caption = "单击按钮" Label1.Visible = False End Sub
Private Sub hello_Click() Label1.Visible = True Label1.Caption = hello.Name End Sub
Button button = sender as button button.Name 就是这样的
{
Button btn = sender as Button;
//btn.Name
}
private void Button1_Click(object sender, EventArgs e)
{
string name = (sender as Button).Name;
// do something with name.
}
初始的时候不可见
当触发click事件的时候是这个label可见 同时将命令按钮的name属性给了label的caption
这里有一个按钮 name 属性为hello
Private Sub Form_Load()
hello.Caption = "单击按钮"
Label1.Visible = False
End Sub
Private Sub hello_Click()
Label1.Visible = True
Label1.Caption = hello.Name
End Sub
Button button = sender as button button.Name
就是这样的