Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Inserting Page Title in HTML Automatically

Reply
Thread Tools

Inserting Page Title in HTML Automatically

 
 
Jonathan Wood
Guest
Posts: n/a
 
      01-02-2008
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

 
Reply With Quote
 
 
 
 
Mark Rae [MVP]
Guest
Posts: n/a
 
      01-02-2008
"Jonathan Wood" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...

> Is this possible?


> xxx <%# Page.Title %> xxx


xxx <%= Page.Title %> xxx

# is databinding syntax...


--
Mark Rae
ASP.NET MVP
http://www.markrae.net

 
Reply With Quote
 
 
 
 
Jonathan Wood
Guest
Posts: n/a
 
      01-02-2008
Playing around with this, I came up with:

<h1><% Response.Write(Page.Title); %></h1>

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" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> 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
>


 
Reply With Quote
 
Peter Bromberg [C# MVP]
Guest
Posts: n/a
 
      01-02-2008
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:
>
> <h1><% Response.Write(Page.Title); %></h1>
>
> 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" <(E-Mail Removed)> wrote in message
> news:%(E-Mail Removed)...
> > 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
> >

>
>

 
Reply With Quote
 
Jonathan Wood
Guest
Posts: n/a
 
      01-02-2008
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

 
Reply With Quote
 
Jonathan Wood
Guest
Posts: n/a
 
      01-02-2008
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

 
Reply With Quote
 
bruce barker
Guest
Posts: n/a
 
      01-02-2008
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

<myControlsageTitle runat="Server">

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
>
>

 
Reply With Quote
 
Jonathan Wood
Guest
Posts: n/a
 
      01-03-2008
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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
>
> <myControlsageTitle runat="Server">
>
> 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
>>
>>


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
I'm looking for html cleaner. Example : convert <h1><span><font>my title</font></span></h1> => <h1>my title</h1>… Stéphane Klein Python 2 03-30-2010 12:35 AM
Re: I'm looking for html cleaner. Example : convert <h1><span><font>my title</font></span></h1> => <h1>my title</h1>… Stefan Behnel Python 0 03-29-2010 08:14 PM
Friendly Urls with page title in (eg. page-title.aspx) anthonykallay@googlemail.com ASP .Net 1 04-24-2007 08:25 AM
How 2 place page title into window title using sitemap in master page? bednar.tomas@gmail.com ASP .Net 0 11-30-2006 03:17 PM
inserting image in title of html page Miguel Angel Javascript 4 09-30-2004 04:53 AM



Advertisments