如何在按钮单击事件中触发动态按钮 [英] how to fire dynamic button in button click event
本文介绍了如何在按钮单击事件中触发动态按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Protected Sub btnView_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnView.Click
con = New SqlConnection(constr)
Dim btnDynamic As New Button
btnDynamic.ID = "btnDynamic"
btnDynamic.Text = "Dynamic Button"
AddHandler btnDynamic.Click, AddressOf OnClick
form1.Controls.Add(btnDynamic)
Private Sub OnClick(ByVal sender As Object, ByVal e As System.EventArgs)
Dim buttonId As String
buttonId = DirectCast(sender, Button).ID
Response.Write("Button clicked: " + buttonId)
End Sub
推荐答案
为什么?只需将已放入click事件处理程序中的代码移至其自己的方法,然后从按钮click处理程序或您需要的其他任何位置调用即可.
完全没有理由单击"按钮来执行一段代码.
Why?? Just move the code that you''ve put in the click event handler to it''s own method and call it from the button click handler or from anywhere else you need to.
There''s very little reason to "Click" a button to execute a piece of code.
无论您希望在何处都可以发出click事件……..
rise the click event wherever you want like this........
btn.Click += new EventHandler(btn_Click);
然后您手动编写以下方法...........
then you manually write the below method...........
protected void btn_Click(objectsender e,Eventargs args)
{
}
简单.........
simple...........
这篇关于如何在按钮单击事件中触发动态按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文