这是我的Form1.cs
文件。该方法应该显示一个MessageBox
点击按钮的ID,但我得到这个错误。按钮不包含定义ID
private void button_Click(object sender, EventArgs e)
{
Button button = sender as Button;
string buttonId = button.ID;
MessageBox.Show(buttonId);
}
错误:
'Button' does not contain a definition for 'ID' and no extension method 'ID' accepting a first argument of type 'Button' could be found (are you missing a using directive or an assembly reference?)
这是一个ASP.NET网站或Windows应用程序? – Nirman
你使用了正确的命名空间吗? – Prabu
这是一个Windows应用程序。 – Alex