ASP.ET 使用语言 VB
我在page_load事件里动态生成了几个linkbutton控件,然后又写了这些动态生成控件的click事件,我在动态生成的linkbutton控件click事件里又动态生成了几个linkbutton控件,但是第二次生成的linkbutton控件click事件无法触发,第一次生成的可以,不知为什么??帮忙解决一下。谢谢
简化代码如下:
Imports System.Web.UI.WebControls
Partial Class BuyPage_test
Inherits System.Web.UI.Page
WithEvents linkbut1 As New LinkButton
WithEvents linkbut2 As New LinkButton
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim linkbut As LinkButton
linkbut = New LinkButton
linkbut.ID = "linkbut1"
linkbut.Text = "Page_Load事件生成"
Panel1.Controls.Add(linkbut)
AddHandler linkbut.Click, AddressOf linkbut1_click
End Sub
'page_load生成的linkbut1的click事件
Protected Sub linkbut1_click(ByVal sender As Object, ByVal e As System.EventArgs) Handles linkbut1.ClickDim linkbut As LinkButton
linkbut = New LinkButton
linkbut.ID = "linkbut2"
linkbut.Text = "Linkbut1_生成"
Panel2.Controls.Add(linkbut)
AddHandler linkbut.Click, AddressOf linkbut2_click
End Sub
'linkbut1的生成的linkbut2的click事件!!!!!!
'就是这个事件没有执行!!!!!!!!!!!!
Protected Sub linkbut2_click(ByVal sender As Object, ByVal e As System.EventArgs) Handles linkbut2.Click
Dim linkbut As LinkButton
linkbut = New LinkButton
linkbut.ID = "linkbut3"
linkbut.Text = "linkbut2_生成"
Panel3.Controls.Add(linkbut)
AddHandler linkbut.Click, AddressOf linkbut1_click
End Sub
End Class