【问题标题】:Handle buttons dropdowns created dynamically处理动态创建的按钮下拉列表
【发布时间】:2016-03-17 20:26:29
【问题描述】:

我已经动态创建了几个按钮和下拉菜单。代码编译得很好,但我的事件处理程序没有触发?这种情况应该怎么处理?

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

Protected Sub btnGo_Click(sender As Object, e As EventArgs) 结束子

Protected Sub ddlBureauDropdowns_SelectedIndexChanged(sender As Object, e As EventArgs) 结束子

【问题讨论】:

  • 通过这些更改,按钮单击事件处理程序对我来说工作得很好。由于您的 AddHandler 语句指向“ddlBureauDropdowns_SelectedIndexChanged”而不是第一个代码 sn-p 下方定义的“ddlBureau_SelectedIndexChanged”,因此您的 DropDownList 的 SelectedIndexChanged 事件处理程序无法工作。
  • 谢谢。那是打字错误

标签: asp.net vb.net


【解决方案1】:

我已将代码移至 Page_init 并为下拉菜单添加了 autopostback = true。事件处理程序现在正在触发。

【讨论】:

    猜你喜欢
    • 2021-05-18
    • 1970-01-01
    • 2016-08-20
    • 1970-01-01
    • 2018-07-22
    • 1970-01-01
    • 2018-11-17
    • 2015-11-06
    • 2018-09-12
    相关资源
    最近更新 更多