Inserting Page Title in HTML Automatically
Inserting Page Title in HTML Automatically
am 02.01.2008 02:29:23 von Jonathan Wood
I'd like to have a page's title appear within the page (ideally, by
inserting something in a master page).
I tried the following:
xxx <%# Page.Title %> xxx
I tried this in both a content page and a master page. It compiles without
error but, in both cases, the two "xxx" showed up with only a space between.
Is this possible? I would really prefer not to use a label that is set from
code.
Thanks.
--
Jonathan Wood
SoftCircuits Programming
http://www.softcircuits.com
Re: Inserting Page Title in HTML Automatically
am 02.01.2008 02:37:17 von mark
"Jonathan Wood" wrote in message
news:%231geq7NTIHA.484@TK2MSFTNGP06.phx.gbl...
> Is this possible?
> xxx <%# Page.Title %> xxx
xxx <%= Page.Title %> xxx
# is databinding syntax...
--
Mark Rae
ASP.NET MVP
http://www.markrae.net
Re: Inserting Page Title in HTML Automatically
am 02.01.2008 02:39:27 von Jonathan Wood
Playing around with this, I came up with:
<% Response.Write(Page.Title); %>
Which seems to work.
Can anyone tell me if this is the most efficient way? In particular, I was
hoping for something the compiler could actually replace the text with the
name of the page, so the code wouldn't be necessary at runtime. But my hunch
is that this would involve that bit of code running everytime the page
loads.
Thanks.
--
Jonathan Wood
SoftCircuits Programming
http://www.softcircuits.com
"Jonathan Wood" wrote in message
news:%231geq7NTIHA.484@TK2MSFTNGP06.phx.gbl...
> I'd like to have a page's title appear within the page (ideally, by
> inserting something in a master page).
>
> I tried the following:
>
> xxx <%# Page.Title %> xxx
>
> I tried this in both a content page and a master page. It compiles without
> error but, in both cases, the two "xxx" showed up with only a space
> between.
>
> Is this possible? I would really prefer not to use a label that is set
> from code.
>
> Thanks.
>
> --
> Jonathan Wood
> SoftCircuits Programming
> http://www.softcircuits.com
>
Re: Inserting Page Title in HTML Automatically
am 02.01.2008 03:13:00 von pbromberg
Jonathan,
I'm not sure I completely understand what your goal is here, but the Page
class in ASP.NET 2.0 has a handy "Title" property, e.g.
Page_Load( xxxx )
{
Page.Title ="This is the Page Title Dood!";
}
-- Peter
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
MetaFinder: http://www.blogmetafinder.com
"Jonathan Wood" wrote:
> Playing around with this, I came up with:
>
>
<% Response.Write(Page.Title); %>
>
> Which seems to work.
>
> Can anyone tell me if this is the most efficient way? In particular, I was
> hoping for something the compiler could actually replace the text with the
> name of the page, so the code wouldn't be necessary at runtime. But my hunch
> is that this would involve that bit of code running everytime the page
> loads.
>
> Thanks.
>
> --
> Jonathan Wood
> SoftCircuits Programming
> http://www.softcircuits.com
>
> "Jonathan Wood" wrote in message
> news:%231geq7NTIHA.484@TK2MSFTNGP06.phx.gbl...
> > I'd like to have a page's title appear within the page (ideally, by
> > inserting something in a master page).
> >
> > I tried the following:
> >
> > xxx <%# Page.Title %> xxx
> >
> > I tried this in both a content page and a master page. It compiles without
> > error but, in both cases, the two "xxx" showed up with only a space
> > between.
> >
> > Is this possible? I would really prefer not to use a label that is set
> > from code.
> >
> > Thanks.
> >
> > --
> > Jonathan Wood
> > SoftCircuits Programming
> > http://www.softcircuits.com
> >
>
>
Re: Inserting Page Title in HTML Automatically
am 02.01.2008 04:36:31 von Jonathan Wood
Peter,
> I'm not sure I completely understand what your goal is here, but the Page
> class in ASP.NET 2.0 has a handy "Title" property, e.g.
>
> Page_Load( xxxx )
> {
> Page.Title ="This is the Page Title Dood!";
> }
I'm not trying to set the title text. I'm trying to insert the title text
within my HTML text.
I could create a label and set the label's text from the Load handler. But
that means that I'll need this little bit of code in every single one of
dozens and dozens of pages. That's why I said I would really prefer not to
use a label that is set from code.
--
Jonathan Wood
SoftCircuits Programming
http://www.softcircuits.com
Re: Inserting Page Title in HTML Automatically
am 02.01.2008 04:38:27 von Jonathan Wood
Mark,
>> Is this possible?
>
>> xxx <%# Page.Title %> xxx
>
> xxx <%= Page.Title %> xxx
>
> # is databinding syntax...
Makes sense. I was trying to duplicate something I'd seen in a gridview
template. I had a hard time finding a good reference on the different
syntaxes and how they are used. (Google won't search on punctuation and the
few books in front of me do not list <% in the index.)
Thanks.
--
Jonathan Wood
SoftCircuits Programming
http://www.softcircuits.com
RE: Inserting Page Title in HTML Automatically
am 02.01.2008 17:45:03 von brucebarker
the easiest and cleanest is to create your own control. just a couple of
lines of code:
public class PageTitle : Label
{
protected override void Render(HtmlTextWriter output)
{
Text = Page.Title;
base.Render(output);
}
}
then you can
anywhere you want the title to render.
-- bruce (sqlwork.com)
"Jonathan Wood" wrote:
> I'd like to have a page's title appear within the page (ideally, by
> inserting something in a master page).
>
> I tried the following:
>
> xxx <%# Page.Title %> xxx
>
> I tried this in both a content page and a master page. It compiles without
> error but, in both cases, the two "xxx" showed up with only a space between.
>
> Is this possible? I would really prefer not to use a label that is set from
> code.
>
> Thanks.
>
> --
> Jonathan Wood
> SoftCircuits Programming
> http://www.softcircuits.com
>
>
Re: Inserting Page Title in HTML Automatically
am 03.01.2008 02:05:59 von Jonathan Wood
I'm not sure if I think that is a better solution, but it is an interesting
approach.
Thanks!
--
Jonathan Wood
SoftCircuits Programming
http://www.softcircuits.com
"bruce barker" wrote in message
news:4A9FFB63-37F9-47AE-B9D2-43A1FAF624FF@microsoft.com...
> the easiest and cleanest is to create your own control. just a couple of
> lines of code:
>
> public class PageTitle : Label
> {
> protected override void Render(HtmlTextWriter output)
> {
> Text = Page.Title;
> base.Render(output);
> }
> }
>
>
> then you can
>
>
>
> anywhere you want the title to render.
>
> -- bruce (sqlwork.com)
>
>
> "Jonathan Wood" wrote:
>
>> I'd like to have a page's title appear within the page (ideally, by
>> inserting something in a master page).
>>
>> I tried the following:
>>
>> xxx <%# Page.Title %> xxx
>>
>> I tried this in both a content page and a master page. It compiles
>> without
>> error but, in both cases, the two "xxx" showed up with only a space
>> between.
>>
>> Is this possible? I would really prefer not to use a label that is set
>> from
>> code.
>>
>> Thanks.
>>
>> --
>> Jonathan Wood
>> SoftCircuits Programming
>> http://www.softcircuits.com
>>
>>