我想使用varible的String值来访问site.master中的控件。该字符串将是控件的名称。
对象的名称是登录,我想将其可见属性修改为 false 。问题是我在字符串中有名字。
Dim name As String = "Login" ' this string comes from the database
name.Visible = True
我在vb.net上使用asp.net。我想要编辑其属性的对象是站点主机中的以下内容:
<a id="Login" runat="server" href="Login.aspx"><img id="Img1" alt="Back to home page" runat="server" src="DynamicData/Content/Images/back.gif" />Login</a>
谢谢大家
答案 0 :(得分:0)
你可以试试这个
<%@ Page Language="VB" %>
<!DOCTYPE>
<script runat="server">
Protected Sub Page_Load(sender As Object, e As System.EventArgs)
'
Dim name As String = "Login" ' this string comes from the database
Dim item As Object
'
For Each item In Me.Controls
If item.id = name Then
item.visible = False
Exit For
End If
Next
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<a id="Login" runat="server" href="default.aspx"><img id="Img1" alt="Back to home page" runat="server" src="DynamicData/Content/Images/back.gif" />Login</a>
</body>
</html>
要检查它是否正常工作,只需重新设置将可见性设置为false的行。