changing the metatags of masterpage from content page

S

Sinan Alkan

In a master page --> content page system, is it possible to change the
"description" and "keywords" meta tags of the master page from content page
?

I am trying as follows, from content page....

protected void Page_Load(object sender, EventArgs e)
{
HtmlMeta fordesc = new HtmlMeta();
fordesc.Name = "keywords";
fordesc.Content = "word1, word2, word3";
Header.Controls.Add(fordesc);
}

But it adds second "keywords" metatag sentence to the page .
How can i just replace or change tags of the master-pages's ?

Thanks in advance...

PS: I'm using c# and framework 2.0
 
N

Nathan Sokalski

I don't know a whole lot about metatags, but I do know that the Add method
is used for appending to a collection, not replacing individual items. What
you basically need to do if you want to replace the metatags is one of the
following:

1. Don't include any metatags in the master page itself, and add all of them
dynamically in the content pages

2. Call the Header.Controls.Clear() method before dynamically adding the
metatags in the content page

3. In the master page's metatags include id and runat="server" attributes so
that you can remove them before adding another metatag in the content page

Note that when using the first two options you will need to add ALL metatags
in the content page. Hopefully this helps.
 

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