Can't access label in MasterPage

C

clintonG

I'm having a problem with a label in a MasterPage which is not in a
ContentPlaceHolder. The naughty label will not allow me to change its text
property.

<%-- renders the label's text directly to the page --%>
<div id="footer">
<asp:Label ID="CurrentTimeLabel" runat="server" Text="CurrentTimeLabel">
</div>

When the control is not in a ContentPlaceHolder I should be able to access
the control directly...

// direct access
CurrentTimeLabel.Text = DateTime.Now.ToString();

When the page is rendered, the label control emits a span in the HTML
source but no text property! So I tried getting a reference to the control.

// should get a reference to a label control that is not in a
ContentPlaceHolder
Label currentTime = (Label)Master.FindControl("CurrentTimeLabel");
currentTime.Text = "Found CurrentTimeLabel";

Still no text being rendered! This is very strange for me. I don't
understand why all of a sudden I can't access the property of a label
in the MasterPage.

<%= Clinton Gallagher
 
C

clintonG

Referencing the control from the Page_PreRender event resolves this issue...

<%= Clinton Gallagher
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top