Calling methods in the Master Page advice

S

Spondishy

Hi,

I have a master page with a literal control. As an example, I'm trying
to set the text of the literal to the current time. In the code behind
for the master page I've got a method that returns the string for the
current time.

So I have this:

<asp:Literal ID="Literal1" runat="server"
Text="<%#GetTime()%>"></asp:Literal>

Unfortunately, this doesn't appear to work in a master page. Any way of
doing this?
 
C

clintonG

// When the control is in the Master
Literal lit = (Literal)Master.FindControl("Literal1");
lit.Text = DateTime.Now( );

// When the control is in a content page we have to use trace to locate the
control in the control hierarchy and use FindControl on each object.

Go to OdeToCode.com there are a series of excellent articles about
MasterPages.

<%= Clinton Gallagher
NET csgallagher AT metromilwaukee.com
URL http://clintongallagher.metromilwaukee.com/
MAP 43°2'17"N 88°2'37"W : 43°2'17"N 88°2'37"W
 

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

Members online

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,143
Latest member
DewittMill
Top