对于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/