changing the metatags of masterpage from content page

Discussion in 'ASP .Net' started by Sinan Alkan, Sep 17, 2008.

  1. Sinan Alkan

    Sinan Alkan Guest

    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
    Sinan Alkan, Sep 17, 2008
    #1
    1. Advertising

  2. 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.
    --
    Nathan Sokalski

    http://www.nathansokalski.com/

    "Sinan Alkan" <> wrote in message
    news:%...
    > 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
    >
    >
    Nathan Sokalski, Sep 17, 2008
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?QWxleCBNYWdoZW4=?=

    MasterPage -> Page -> MasterPage Code Access

    =?Utf-8?B?QWxleCBNYWdoZW4=?=, Apr 10, 2006, in forum: ASP .Net
    Replies:
    3
    Views:
    7,889
    Steven Cheng[MSFT]
    Apr 14, 2006
  2. =?Utf-8?B?bXVzb3NkZXY=?=

    Controlling Title and Metatags when using MasterPage

    =?Utf-8?B?bXVzb3NkZXY=?=, Jun 25, 2006, in forum: ASP .Net
    Replies:
    5
    Views:
    11,362
    wbirt
    May 6, 2009
  3. Gary
    Replies:
    4
    Views:
    434
    Jukka K. Korpela
    Nov 3, 2006
  4. Torben Laursen
    Replies:
    4
    Views:
    573
    clintonG
    Mar 15, 2008
  5. pvong

    MasterPage changing Content Page

    pvong, Nov 28, 2008, in forum: ASP .Net
    Replies:
    18
    Views:
    968
    Hillbilly
    Dec 8, 2008
Loading...

Share This Page