Controlling the Rendering of Dynamic Meta Tags on a Master Page

Last post 02-13-2008 4:16 AM by sdchown. 6 replies.

Sort Posts:

  • Controlling the Rendering of Dynamic Meta Tags on a Master Page

    02-09-2008, 3:11 AM
    • Member
      point Member
    • sdchown
    • Member since 02-09-2008, 3:08 AM
    • Posts 4

    I am changing the Meta Description and Meta Keywords at runtime. However when it renders (and I view source) it runs them all into one line instead of keeping them on seperate lines. Is there any way to control this?

    My SEO guys want them to be on their own lines...don't ask!

     Thanks in advance.

    Stephen

     

     

  • Re: Controlling the Rendering of Dynamic Meta Tags on a Master Page

    02-09-2008, 3:43 AM
    • Member
      121 point Member
    • David Luu
    • Member since 10-26-2006, 8:49 PM
    • Toronto, Ontario
    • Posts 29

    Haha ... are you dynamically creating the tags or are they already specified in the masterpage e.g. <meta id='mDesc' runat='server' name='description' content="" /> ? I would choose the latter method since you only need one meta description and one meta keywords tags.

    David Luu
    Real Estate Sales Representative & .NET Developer
    Website: www.condolicious.com
  • Re: Controlling the Rendering of Dynamic Meta Tags on a Master Page

    02-09-2008, 3:53 AM
    • Member
      point Member
    • sdchown
    • Member since 02-09-2008, 3:08 AM
    • Posts 4

    Yes.

    They're specified in the masterpage thusly :

     <head runat="server">

    <title></title>

    <link href="Main.css" rel="stylesheet" type="text/css" />

     

    <meta name="description" content="description" id="metaDescription" runat="server" />

     

    <meta name="keywords" content="keywords" id="metaKeywords" runat="server" />

     

    And set thusly:

    If sTitle = "" Then sTitle = Util.GetPageName(iPage)

    If sKeywords = "" Then sKeywords = Util.GetDomainMetaKeywords()

    If sDescription = "" Then sDescription = Util.GetDomainMetaKeywords()

    metaDescription.Attributes("content") = sDescription

    metaKeywords.Attributes("content") = sKeywords

    Me.Page.Title = sTitle

     

    But when rendered they appear like this :

     

    <link href="Main.css" rel="stylesheet" type="text/css" /><meta id="ctl00_metaDescription" name="description" content="" /><meta id="ctl00_metaKeywords" name="keywords" content="" />  

     

    All on one line.

    I hope I've explained myself a bit better now. Getting *extremely* frustrated with it. ;-)

     

  • Re: Controlling the Rendering of Dynamic Meta Tags on a Master Page

    02-12-2008, 3:32 PM
    • Member
      121 point Member
    • David Luu
    • Member since 10-26-2006, 8:49 PM
    • Toronto, Ontario
    • Posts 29

    Try removing runat="server" from the head control.  That should keep the tags from bunching together.

    David Luu
    Real Estate Sales Representative & .NET Developer
    Website: www.condolicious.com
  • Re: Controlling the Rendering of Dynamic Meta Tags on a Master Page

    02-12-2008, 4:05 PM
    • Member
      point Member
    • sdchown
    • Member since 02-09-2008, 3:08 AM
    • Posts 4

    Will also stop the project compiling as I use themes I need runat="server" in the header.

  • Re: Controlling the Rendering of Dynamic Meta Tags on a Master Page

    02-12-2008, 9:41 PM
    Answer
    • Member
      106 point Member
    • Jack Whitney
    • Member since 02-11-2008, 10:38 PM
    • Posts 20

    Here is an option.

            // Create Meta Description
            HtmlMeta metaDesc = new HtmlMeta();
            metaDesc.Name = "description";
            metaDesc.Content = "description";
           
            // Create Meta Keywords
            HtmlMeta metaKeywords = new HtmlMeta();
            metaKeywords.Name = "keywords";
            metaKeywords.Content = "keywords";

            // Add Meta controls to HtmlHead
            HtmlHead head = (HtmlHead)Page.Header;
            head.Controls.Add(new LiteralControl("\n"));
            head.Controls.Add(metaDesc);
            head.Controls.Add(new LiteralControl("\n"));
            head.Controls.Add(metaKeywords);
            head.Controls.Add(new LiteralControl("\n"));

    Hope this helps.

    ~Jack 

  • Re: Controlling the Rendering of Dynamic Meta Tags on a Master Page

    02-13-2008, 4:16 AM
    • Member
      point Member
    • sdchown
    • Member since 02-09-2008, 3:08 AM
    • Posts 4

    Jack! You're my hero! With a bit of modification - I needed the Meta Tags at the top of the header area (see below) that works great. Well done and thanks. 

    ' Create Meta Description

    Dim metaDesc As New HtmlMeta

    metaDesc.Name = "description"

    metaDesc.Content = sDescription

     

    'Create Meta Keywords

    Dim metaKeywords As New HtmlMeta

    metaKeywords.Name = "keywords"

    metaKeywords.Content = sKeywords

     

     

    ' Add Meta controls to HtmlHead

    headMain.Controls.AddAt(1, New LiteralControl(Chr(13)))headMain.Controls.AddAt(1, New LiteralControl(Chr(13)))

    headMain.Controls.AddAt(1, metaDesc)

    headMain.Controls.AddAt(1,
    New LiteralControl(Chr(13)))

    headMain.Controls.AddAt(1, metaKeywords)

    headMain.Controls.AddAt(1, New LiteralControl(Chr(13)))

    headMain.Controls.AddAt(1, New LiteralControl(Chr(13)))

     

Page 1 of 1 (7 items)