I'm trying to reference a Literal control inside a ContentPlaceHolder on my Master page from a client page using the following code:
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
This is from my Master page:
<div id="div1" class="main" runat="server">
<asp:ContentPlaceHolder ID="MainContent" runat="server">
<asp:Literal ID="Literal1" runat="server"></asp:Literal>
</asp:ContentPlaceHolder>
</div>
The code finds the MainContent control fine, but the Literal control keeps coming back as Nothing. Any idea what I'm doing wrong? This seems like it should be easy but apparently I'm wrong.
Thanks, Gina