How/were to add Meta Tag in child page

Last post 08-25-2006 7:56 PM by SuperGhost. 6 replies.

Sort Posts:

  • How/were to add Meta Tag in child page

    07-12-2006, 6:57 PM
    • Member
      14 point Member
    • MrShrek
    • Member since 07-08-2006, 12:01 PM
    • Posts 36

    I have a master page with a number of child pages, I would like to know how to add different keyword Meta tags to each page,

    I use VB, and a codebehind page if this is relavant.

    Thanks for help in advance

     

    Steve

  • Re: How/were to add Meta Tag in child page

    07-12-2006, 9:08 PM
    • Star
      8,834 point Star
    • MorningZ
    • Member since 07-22-2002, 2:39 PM
    • Fort Lauderdale, FL
    • Posts 1,815
    "If you make it idiot proof, they'll build a better idiot"
  • Re: How/were to add Meta Tag in child page

    07-13-2006, 5:54 AM
    • Member
      14 point Member
    • MrShrek
    • Member since 07-08-2006, 12:01 PM
    • Posts 36

     might be an idiot, but I don't care to admint it :)

    The problem with this code is that if java script is turned off the code will not work.

     

    Any other solutions please

  • Re: How/were to add Meta Tag in child page

    07-13-2006, 9:17 AM
    • Star
      8,834 point Star
    • MorningZ
    • Member since 07-22-2002, 2:39 PM
    • Fort Lauderdale, FL
    • Posts 1,815

    Maybe you should look at the page again, where you'll see

    Meta tag
    HtmlMeta meta = new HtmlMeta();
    meta.Name = "keywords";
    meta.Content = "Your keywords here";
    this.Header.Controls.Add(meta);

    Maybe i'm just crazy, but i don't see anything even remotely concerning javascript in that snip of code that deals with adding a Meta tage from the child page (isn't this what you asked for?)

    "If you make it idiot proof, they'll build a better idiot"
  • Re: How/were to add Meta Tag in child page

    07-18-2006, 5:52 PM
    • Participant
      1,410 point Participant
    • StevenSw
    • Member since 08-19-2002, 8:04 PM
    • Opelika, AL
    • Posts 278

    This is much simplier than you think. Foe example here is a snippet that fires in a web form that is using a master page.

    protected void Page_Load(object sender, EventArgs e)
    {
        System.Web.UI.HtmlControls.HtmlMeta _metaTag = new HtmlMeta();
        System.Web.UI.HtmlControls.HtmlHead _head = (HtmlHead)Page.Header;

        _metaTag.Name = "keywords";
        _metaTag.Content = "C#, VB.NET, ASP.NET";
        _head.Controls.Add(_metaTag);
    }

    See: HtmlHead Class

    The output is as follows: meta name="keywords" content="C#, VB.NET, ASP.NET"

    HTH,
    Steven

    Steven M. Swafford
    http://radicaldevelopment.net

    Dont forget to click "Mark as Answer" on the post that helped you.
  • Re: How/were to add Meta Tag in child page

    08-25-2006, 12:44 PM
    • Member
      148 point Member
    • relish27
    • Member since 06-12-2006, 2:15 AM
    • Posts 46
    hello.  i have been able to get this to work... however, i woudl like to create a class with this functionality in it, so that i could just call a function from each of the content pages and not have to have the code above on each content page's page_load.

    so, again, the idea:

    1.  create metatags.cs class
    2.  call a function from page_load of content page that passes the keywords and description
    3.  metatags class function does the work

    this all seems great, except i get an error in the class in reference to that Page.Header call above.  i'm wondering if i need to pass something else in in order to make a reference to the Page.Header in a different way?  any ideas?

    thanks, c

  • Re: How/were to add Meta Tag in child page

    08-25-2006, 7:56 PM
    • Participant
      1,738 point Participant
    • SuperGhost
    • Member since 12-29-2005, 11:58 AM
    • Palmdale CA, USA
    • Posts 409

    Relish, its always good to let us know what error you're receiving. However seeing what you're asking it seems you just need to pass a reference to the Page object in your function. Example:

    (Assuming your function is Shared)

    MyMetaTagHandler.SetMetaTags(Page)

    ** Hope this helps!

    DennyDotNet
    Social42.com
Page 1 of 1 (7 items)