ASP.NET 如何使用控件进行 For 循环

标签 asp.net

对于Page.Header.Controls中的每个控件

目前出现错误,我该怎么做? “控件是一种类型,不能用作表达式”

完整代码如下

Try
        ' I only do this on my production servers, so I declare those here.'
        If Request.ServerVariables("server_name") = "www.myproductionurl.com" Then
            ' Allow scripts and css to logged in CMS users'

            Dim checkLogin As New Controls.Login
            If checkLogin.IsLoggedIn <> True Then
                For Each Control In Page.Header.Controls
                    If Control.GetType.Name = "EktronJsControl" Or Control.GetType.Name = "EktronCssControl" Or Control.GetType.Name = "EktronModalCss" Then
                        Page.Header.Controls.Remove(Control)
                    Else
                        ' Removes the extra bubble inline style stuff that wasn't put in a CSS.''
                        Dim litControl As LiteralControl = Control
                        If litControl.Text = Nothing Then
                            litControl.Text = ""
                        End If

                        ' Removing blank.css file'
                        Dim htmlLink As HtmlLink = Control
                        If htmlLink.Href = "/css/blank.css" Then
                            Page.Header.Controls.Remove(Control)
                        End If
                    End If
                Next
            End If
        End If
    Catch ex As Exception

    End Try`

最佳答案

遗憾的是...VB.NET编译器说你不能使用“Control”作为变量名,因为“Control”也是一种类型!

只需使用另一个标识符:)

关于ASP.NET 如何使用控件进行 For 循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5247619/

相关文章:

javascript - .NET MVC 多路由问题

c# - 我如何最好地重构此 C# 代码?

c# - 像 Google (ASP) 一样在文本框下方的下拉列表中搜索结果

html - CSS 适用于在 firefox 中工作的 aspx 页面,但不适用于 IE。只有 1 个按钮的样式不起作用。有任何想法吗?

c# - ASP.NET Core/EF Core/xUnit.NET 集成测试中每个测试的种子测试数据

c# - 为什么 ValidateRequest ="true"不足以预防 XSS?

javascript - 寻找支持链接事件的图表库

c# - TinyMCE 包

javascript - 获取选中的输入复选框的 id 并添加到列表中

用于 jpg 文件的 ASP.net MVC 3 路由