【问题标题】:In VB.NET, How to listen to the load event of any dropdown list in the application?在 VB.NET 中,如何监听应用程序中任何下拉列表的加载事件?
【发布时间】:2017-11-17 11:18:31
【问题描述】:

我在应用的不同页面中有几个下拉列表。

我需要在整个应用程序中加载任何下拉菜单时运行一些功能

我正在尝试以下但不工作:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    GetAllDropdowns(Me.Page)
End Sub

Private Sub GetAllDropdowns(ByVal Ctrl As Control)
    Dim dd As DropDownList = Nothing
    For Each c In Ctrl.Controls
        If TypeOf c Is DropDownList Then
            dd = DirectCast(c, DropDownList)
            AddHandler dd.Load, AddressOf doIt
        Else
            GetAllDropdowns(c)
        End If
    Next
End Sub

Private Sub doIt(ByVal sender As Object, ByVal e As EventArgs)
    'Do whatever....
End Sub

【问题讨论】:

  • 也许提供一些代码?这个问题无法回答,因为它太宽泛了。
  • 请检查更新后的帖子

标签: asp.net vb.net visual-studio-2010


【解决方案1】:

我认为问题在于您正在使用的事件。

Page_Load 事件在控件的所有加载事件之后运行,因此子 doIT 不会运行。

尝试在似乎更适合此任务的 Page_Init 事件中移动您的代码。

有关 asp.net 页面生命周期的更多信息,请参阅here

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-08-22
    • 2019-02-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多