473,395 Members | 1,692 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Can't access label in MasterPage

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
Jan 30 '06 #1
1 2015
Referencing the control from the Page_PreRender event resolves this issue...

<%= Clinton Gallagher

"clintonG" <cs*********@REMOVETHISTEXTmetromilwaukee.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
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

Feb 1 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: phil1bruening | last post by:
Hello! I need to access content page controls from within the master page. How can I do that??
5
by: Mikaël PLOUHINEC | last post by:
Hello, I have a master page with a label. In the "children page" in the Page_Load function for example, I would like to change the text of the label in the master page. Is that possible? How...
3
by: james | last post by:
Hey Guys, Do you have any idea how to acces Request.QueryString in a MasterPage? I need to use it to modify my sitemap. My code is: public partial class MasterPage :...
1
by: cruster | last post by:
Hey folks. I'd like to know if it's possible to define a method in masterpage codebehind and then call it from the page, who uses the masterpage via Master.something maybe. Thanks.
2
by: bonokoot | last post by:
Hello, I have a MasterPage with a Label that I want to display a custom description of the page and when the user clicks to different links on my website I would like that description to change....
4
by: Phil | last post by:
Hi, How to add programmatically a label into a content page? I tried this but doesn't work: Thanks Phil content page:
4
by: Ben | last post by:
Hi, i have some problem to access from code-behind a label nested into a CreateWizard control. I use a html-table for align purpose only. I try to change the text property of the label with...
1
by: StevenT | last post by:
I have searched everywhere and found a lot of information on this but nothing that can fix my problem. This is my shopping cart HTML, I eventually realised I dont need a form tag here because I...
6
by: =?Utf-8?B?SmF5IFBvbmR5?= | last post by:
I am trying to access a Public property on a Master Page from a Base Page. On the content pages I have the MasterType Directive set up as follows: <%@ MasterType virtualpath="~/Master.master" %>...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.