Controlling Title and Metatags when using MasterPage


G

Guest

Hi guys

I'm using a MasterPage for my website rebuild (vs2005, .net2, c#).

I want to be able to control the Title element, both on the MasterPage and
the Content pages. For example, on each page I want the following to appear
for the Title..

SITENAME - some page related title

Obviously, I could just code each page to have "SITENAME - " in, but I'm
trying to find a way of being able to do something like..

this.Title += "some page related title"

... where the "SITENAME - " part has been added by the MasterPage. Can't get
this to work though.. any ideas? If I add to the <title> element of the
MasterPage, then it gets over written by the content, and i end up with

"Untitled Pagesome page related title"

and if I add Page.Title in the MasterPage .cs, then that overrides the title
for the ContentPage, so I end up with

"SITENAME - "

Arrrrgh! Help much appreciated! :eek:) While were on the subject, how can I
change metadata (keywords, description, etc) for each Content page? Can I
just do that directly from the .cs?

Cheers


Dan
 
Ad

Advertisements

W

Walter Wang [MSFT]

Hi Dan,

Thank you for your post.

Based on my understanding, the questions are:
1) How to change page title of a content page while using master page?
2) How to add meta keywords from content page?
If I've misunderstood anything, please feel free to post here.

I think you can change the page title in the master page's PreRender event:

protected void Page_Load(object sender, EventArgs e)
{
PreRender += new EventHandler(MasterPage_PreRender);
}

void MasterPage_PreRender(object sender, EventArgs e)
{
Page.Title = "Master - " + Page.Title;
}

As for the meta keywords, there're several ways to achieve this, you can
find more information here:

#Master Pages: Tips, Tricks, and Traps
http://odetocode.com/Articles/450.aspx

Hope this helps. Please feel free to post here if anything is unclear.

Regards,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
W

Walter Wang [MSFT]

Hi Dan,

Appreciate your update and response. I am glad to hear that the problem has
been fixed. If you have any other questions or concerns, please do not
hesitate to contact us. It is always our pleasure to be of assistance.

Have a nice day!


Regards,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
Joined
Feb 24, 2009
Messages
1
Reaction score
0
Controlling Title When Using MasterPage

Your solution code is

expvice.com/code.aspx?id=13
 
Ad

Advertisements

Joined
May 6, 2009
Messages
1
Reaction score
0
MasterPages and Dynamic Title Changes

Hi,

I am also struggling with the document.Title or Page.title issue. I have a master page and seven content placeholders for my controls. I populate a GridView with members from the Database and when a Member is selected load the data into tab dialogs. My drawback is that I need the selected members Name in the Document / Page title and cannot get it to work.

Have tried client javascript ans server side code with no luck. I am using vb

Any Help from anyone would greatly be appreciated.

Thanks,

William Birt Sr.
Senior Software Engineer
MedExpress Information Systems
 
Ad

Advertisements


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

Top