【问题标题】:Empty Update Panel Controls空更新面板控件
【发布时间】:2014-06-18 10:23:33
【问题描述】:

我正在使用 modalpopupextender 进行一个项目,该项目控制更新面板。我想清空所有文本框并将所有下拉列表和单选按钮列表置于默认状态。我使用了以下代码:

PnlAssets.Controls.Clear()

但是这段代码清空了所有文本框以及下拉列表和单选按钮列表,之后我在服务器端绑定的下拉列表中得到一个空列表。仅供参考,我在浏览器端使用 ASP.NET。谢谢。

【问题讨论】:

    标签: asp.net vb.net updatepanel panel


    【解决方案1】:

    可能有更好的选择,但这是我处理类似问题的方法。我有一个带有扩展模块的通用网络库。例如,我在其中编写了一个 RecursiveControlList 函数,它为我提供了给定面板中的所有控件。

        ''' <summary>
        ''' Returns a recursive list of controls inside the current control.
        ''' </summary>
        ''' <param name="control">The control.</param>
        ''' <returns></returns>
        <Extension()> _
        Public Function RecursiveControlList(ByVal control As Control) As Generic.List(Of Control)
            Dim lst As New Generic.List(Of Control)
            Return DoRecursiveControlList(control, lst)
        End Function
    
        Private Function DoRecursiveControlList(ByVal control As Control, ByVal currentList As Generic.List(Of Control)) As Generic.List(Of Control)
            If Not control Is Nothing Then
                For Each child As Control In control.Controls()
                    currentList.Add(child)
                    DoRecursiveControlList(child, currentList)
                Next
            End If
    
            Return currentList
        End Function
    

    要清除您的控件,您可以使用类似于以下内容的内容:

        For Each control as System.Web.UI.Control In PnlAssets.RecursiveControlList()
               If control.GetType Is GetType(TextBox) Then
                   CType(control, TextBox).Text = String.Empty
               ElseIf control.GetType IS GetType(DropDownList) Then
                   CType(control, DropDownList).ClearSelection()
               End If
        Next
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2010-10-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-19
      相关资源
      最近更新 更多