我尝试使用以下代码从客户端页面在我的母版页上的ContentPlaceHolder中引用Literal控件:
Private Sub TestMsgBox()
Dim mpContentPlaceHolder As ContentPlaceHolder
Dim mpLiteral As Literal
mpContentPlaceHolder = CType(Master.FindControl("MainContent"), ContentPlaceHolder)
If Not mpContentPlaceHolder Is Nothing Then
mpLiteral = CType(mpContentPlaceHolder.FindControl("Literal1"), Literal)
If Not mpLiteral Is Nothing Then
mpLiteral.Text = "Some Text"
End If
End If
End Sub
这是来自我的母版页:
<div id="div1" class="main" runat="server">
<asp:ContentPlaceHolder ID="MainContent" runat="server">
<asp:Literal ID="Literal1" runat="server"></asp:Literal>
</asp:ContentPlaceHolder>
</div>
代码发现MainContent控件很好,但Literal控件一直没有返回。知道我做错了什么吗?这似乎应该很容易,但显然我错了。
谢谢, 吉娜