如何使窗体中的所有按钮仅在vb.net中触发一个buttonclick事件 [英] how to make all buttons in a form fire only one buttonclick event in vb.net
本文介绍了如何使窗体中的所有按钮仅在vb.net中触发一个buttonclick事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好.
我的aspx中有大约700个按钮.所有按钮都将执行相同的事件,因此我只想声明一个buttonclick事件,以便所有按钮都将触发该唯一事件.我该怎么办?
Tq!
Hello all.
I have about 700 buttons in my aspx. All buttons will do the same event so I want to declare only one buttonclick event so that all buttons will fire to that only event. How can I do that?
Tq!
推荐答案
您可以声明任意数量的按钮并分配1个onclick函数:)
经过测试的4个按钮
You can declare as many buttons you want and assign 1 onclick function :)
Tested for 4 buttons
<asp:Button ID="btn1" runat="server" Text="btn1" onclick="btn1_Click" />
<asp:Button ID="Button1" runat="server" Text="btn1" onclick="btn1_Click" />
<asp:Button ID="Button2" runat="server" Text="btn1" onclick="btn1_Click" />
<asp:Button ID="Button3" runat="server" Text="btn1" onclick="btn1_Click" />
定义单个按钮单击事件处理程序并将该处理程序附加到所有按钮.
Define a single button Click event handler and attach that handler to all the buttons.
btn1.Click += new EventHandler(this.GenericBtn_Click);
btn2.Click += new EventHandler(this.GenericBtn_Click);
btn3.Click += new EventHandler(this.GenericBtn_Click);
btn4.Click += new EventHandler(this.GenericBtn_Click);
.
.
.
btnn.Click += new EventHandler(this.GenericBtn_Click);
void GenericBtn_Click(Object sender, EventArgs e)
{
// all button clicks land here!
}
参考: MSDN:Button.Click事件 [ ^ ]
Refer: MSDN: Button.Click Event[^]
定义单个按钮单击事件处理程序,并将该处理程序附加到所有按钮.
Define a single button Click event handler and attach that handler to all the buttons.
btn1.Click += new EventHandler(this.GenericBtn_Click);
btn2.Click += new EventHandler(this.GenericBtn_Click);
btn3.Click += new EventHandler(this.GenericBtn_Click);
btn4.Click += new EventHandler(this.GenericBtn_Click);
.
.
.
btnn.Click += new EventHandler(this.GenericBtn_Click);
void GenericBtn_Click(Object sender, EventArgs e)
{
// all button clicks land here!
}
参考: MSDN:Button.Click事件 [ ^ ]
Refer: MSDN: Button.Click Event[^]
这篇关于如何使窗体中的所有按钮仅在vb.net中触发一个buttonclick事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文