首页 > 解决方案 > VB.NET Control.find 控件查找指定容器外的控件

问题描述

我正在维护一个旧的 aspx 系统,它使用一个函数来识别是否在 aspx 页面中创建了动态控件。不过,它似乎是在指定容器之外找到控件。有没有人以前出现过这种情况,或者知道为什么会发生这种情况?

Public Shared Function controlExists(ByVal container As Control, ByVal controlname As String) As Boolean

        Dim Control As Control = Nothing

        controlExists = True

        Try

            Control = container.FindControl(controlname)

            If IsNothing(Control) Then

                controlExists = False

            End If

        Catch ex As Exception

            Throw ex

        End Try



    End Function

我传入一个带有 runat 服务器的 HTML div 作为容器,然后我知道的下拉列表的名称位于 div 之外。但 controlExists 返回 true,即使它应该为 false。

标签: htmlasp.net

解决方案


推荐阅读