我创建了一个名为btn的动态按钮。 btn的处理程序调用一个函数来生成一个名为secondbtn的动态按钮。 secondbtn与一个事件处理程序相关联,该处理程序应在屏幕上打印“请工作”。当我运行程序时,会创建第一个名为btn的动态按钮,当我单击btn时,它会触发生成secondbtn的btn的事件处理程序。当我点击secondbtn时,secondbtn消失了。我附上了我的代码
Function generateEntireForm(ByVal panelOne As Panel)
Dim btn As New Button
panelOne.ID = "tstpanelID"
btn.ID = "test1"
btn.Text = "First"
AddHandler btn.Click, AddressOf Test
panelOne.Controls.Add(btn)
End Function
Public Sub Test(sender As Object, e As EventArgs)
Dim panelBox As Panel = DirectCast(sender.FindControl("tstpanelID"), Panel)
generateTopPanelForSearchMode(panelBox)
End Sub
Function generateTopPanelForSearchMode(ByVal firstpanel As Panel)
Dim secondbtn As New Button
secondbtn.ID = "Second"
secondbtn.Text = "Second"
AddHandler secondbtn.Click, AddressOf TestTwo
firstpanel.Controls.Add(secondbtn)
End Function
Public Sub TestTwo(sender As Object, e As EventArgs)
System.Diagnostics.Debug.WriteLine("Please work")
End Sub
感谢您的帮助!