Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net 动态创建的句柄按钮下拉列表_Asp.net_Vb.net - Fatal编程技术网

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”。谢谢。那是打字错误