views:

45

answers:

1

Hi,

I've got a master page setup with a contentplaceholder control inside the title tag as so:

<head id="head1" runat="server">
 <style type="text/css">
  body { font-family: Tahoma; font-size: 9pt; }
 </style>

 <title><asp:contentplaceholder id="title" runat="server" /></title>
</head>

That contentplaceholder is implemented inside a page that uses that masterpage as so:

<asp:content runat="server" contentplaceholderid="title">
    Welcome: <%= this.BasketID %>
</asp:content>

I'm trying to then get a copy of the substituted title inside the masterpage body (also tried inside the page - and this doesnt work either) like:

<p>
    <strong>Subject:</strong> <%# Page.Title %>
</p>

In all cases Page.Title and Page.Header.Title are "" (I've tried both databinding and using the <%= %> syntax to no avail.

Does anyone know what is going on here and how I can overcome this?

Thanks.

+1  A: 

The problem you're getting is because you are 'tricking' the page cycle. You'd better use this in the codebehind of the page:

Master.Title = "Welcome: " + basketId

You could do it this way however; on the masterpage: create a HtmlTextWriter, configure it to write to a MemoryStream. Render the 'title' contentplaceholder to the HtmlTextWriter, attach a StreamReader to the stream to grab the content as a string, and output this to your page. Yet, this is not efficient, and way too much work :-)

Jan Jongboom
I thought I must have been doing something 'out of order', its these little things that drive me mad about WebForms sometimes! :) Thanks for the advice.
Kieran Benton