Asp.net 动态创建的句柄按钮下拉列表
我动态创建了几个按钮和下拉列表。代码编译很好,但我的事件处理程序没有启动?我该如何处理这种情况Asp.net 动态创建的句柄按钮下拉列表,asp.net,vb.net,Asp.net,Vb.net,我动态创建了几个按钮和下拉列表。代码编译很好,但我的事件处理程序没有启动?我该如何处理这种情况 Protected Sub CreateAndLoadDropdowns() Dim ddlBureauDropdowns As New DropDownList Dim btnGo As New Button With btnGo .Text = "Go" .ID = tempList2
Protected Sub CreateAndLoadDropdowns()
Dim ddlBureauDropdowns As New DropDownList
Dim btnGo As New Button
With btnGo
.Text = "Go"
.ID = tempList2(0).MenuID
End With
AddHandler btnGo.Click, AddressOf Me.btnGo_Click
AddHandler ddlBureauDropdowns.SelectedIndexChanged, AddressOf Me.ddlBureauDropdowns_SelectedIndexChanged
phAddDropdnsHere.Controls.Add(ddlBureauDropdowns)
phAddDropdnsHere.Controls.Add(btnGo)
Next
End Sub
受保护的子btnGo_单击(发送者作为对象,e作为事件参数)
端接头
受保护的子数据库删除\u SelectedIndexChanged(发件人作为对象,e作为事件参数)
End Sub我已将代码移到Page_init,并为下拉列表添加了autopostback=true。事件处理程序现在正在启动。通过这些更改,按钮单击事件处理程序对我来说工作正常。DropDownList的SelectedIndexChanged事件处理程序无法工作,因为AddHandler语句指向的是“ddlbreaudropdowns\u SelectedIndexChanged”,而不是第一个代码段下面定义的“ddlbreau\u SelectedIndexChanged”。谢谢。那是打字错误