I'm still new to master pages, but I know of two ways to control a master pages title or meta tags. One was mentioned in a previous post (adding a content placeholder to the head section of the master page). Here is another that someone showed to me:
The following code in the code behind file of the master page:
HtmlMeta theMetaTag = new HtmlMeta();
theMetaTag.Attributes.Add("name", "test");
theMetaTag.Attributes.Add("content", "this is a test");
Page.Header.Controls.Add(theMetaTag);
will generate this tag in the head section of the page:
<meta name="test" content="this is a test" />
In order to give more control (if that is necessary), create a public property in the master page that controls this meta tag. For instance, I have worked on pages where we have boolean properties to tell whether or not an optional meta tag is rendered, or string properties to tell what should go in the content attribute of a required meta tag.
So if you want the meta tag to be optional, add this property to the master page:
public property bool UseMetaTag
{
get
{
object o = ViewState["usemetatag"];
return o==null?string.empty:(string)o;
}
set
{
ViewState["usemetatag"] = value;
}
}
(I am doing this from memory so I hope I got that right.)
Then you just set it in the content page's code behind:
Master.UseMetaTag = true;
and make the code above conditional:
if (this.UseMetaTag)
{
HtmlMeta theMetaTag = new HtmlMeta();
...
}
As far as setting the title dynamically, I created this property in a master page and set it in the content page:
public String PageTitle
{
get
{
return Page.Header.Title;
}
set
{
Page.Header.Title = value;
}
}
I hope this is at least somewhat helpful:)
I would, of course, be interested if someone knows of a better or different way.