我在我的aspx页面中有这些:
<input runat="server" name="btnSubmit" id="btnSubmit" value="Submit" type="submit" OnServerClick="ibtn_Click" />
<input runat="server" name="btnCancel" id="btnCancel" value="Cancel" type="submit" OnServerClick="ibtn_Click" />
在方法“ibtn_Click”中的代码后面,我添加了这一行来获取特定按钮的id:
HtmlGenericControl btn = sender as HtmlGenericControl;
但我收到错误消息“使用'new'关键字来创建对象实例。”
答案 0 :(得分:2)
试试这个:
protected void ibtn_Click(object sender, EventArgs e)
{
HtmlInputButton input = (HtmlInputButton)sender as HtmlInputButton;
string ControlID = input.ID.ToString();
}