方法一: 直接指定 事件
<asp:Button ID="btn1" runat="server" Text="按钮1" onclick="btn1_Click" /><br /><br /><br />
<asp:Button ID="btn2" runat="server" Text="按钮2" onclick="btn1_Click" />
方法二:后台添加
protected void Page_Load(object sender, EventArgs e)
{
Button btn;
btn= new Button();
btn.ID = "btn1";
btn.Text = "按钮1";
this.form1.Controls.Add(btn);
btn.Click += new EventHandler(btn1_Click);
btn = new Button();
btn.ID = "btn2";
btn.Text = "按钮2";
this.form1.Controls.Add(btn);
btn.Click += new EventHandler(btn1_Click);
}
protected void btn1_Click(object sender, EventArgs e)
{
Page.ClientScript.RegisterStartupScript(Page.GetType(), "", "<script language=\"javascript\">alert('点击了按钮事件');</script>");
}
温馨提示:内容为网友见解,仅供参考