locked
Dynamic Meta Description on ShowAd Page? RRS feed

  • Question

  • User1988740161 posted

    I'm trying to make the description for ads change dynamically so every ad will have a unique description.  I've been pouring through the web and various blogs and forums and still can't figure this out.  I've tried several methods with no luck.  Here's my latest... 

    ShowAd.aspx

    <%@ Page Language="VB" MasterPageFile="~/AirportMaster.master" CodeFile="ShowAd.aspx.vb"
     Inherits="ShowAd_aspx" Title=" " Description=" "%>
    <asp:Content ID="myTag" ContentPlaceHolderID="head1" runat="Server" >
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

    <meta name="description" content="">
    <meta name="keywords" content= "">
    </asp:Content>

     

    ShowAd.vb

     

    metaDescription.Name =

    Dim metaDescription As New HtmlMeta()"description"

    metaDescription.Content = "Ad.Title"

    Page.Header.Controls.Add(metaDescription)

     

    It compiles ok, but doesn't work.  I'm sure I'm missing something basic, but just can't figure it out.  Has anyone done this already with the classified kit?  I'd really appreciate a hint in the right direction.  Thanks

     

     

     

     

     

     

     

    Friday, November 13, 2009 2:39 AM

Answers

  • User730446648 posted

    You were on the right track, but you messed up adding the quotes.

    This "ad.Title" makes it write whatever is between the quotes.
    This ad.Title with no quotes tells it to get the the actual Title for your add.
    And another useful thing at times is to do both.

    ad.Title + ", Some static code here. " + ad.Description

    Good Luck

    -Daniel

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, November 13, 2009 10:47 AM

All replies

  • User1037547548 posted

    hey.

    try this code.

    // Create HtmlHead object.
    HtmlHead head = (System.Web.UI.HtmlControls.HtmlHead)Header;
    
    //Create HtmlMeta Object.
    HtmlMeta meta = new HtmlMeta();
    
    //Add Attributes to Meta tags.
    meta.Attributes.Add("content", "MetaDescriptionHere");
    meta.Attributes.Add("name", "description");
    
    //Add meta tag to html header.
    head.Controls.Add(meta);

    Regard


    Friday, November 13, 2009 5:38 AM
  • User730446648 posted

    You were on the right track, but you messed up adding the quotes.

    This "ad.Title" makes it write whatever is between the quotes.
    This ad.Title with no quotes tells it to get the the actual Title for your add.
    And another useful thing at times is to do both.

    ad.Title + ", Some static code here. " + ad.Description

    Good Luck

    -Daniel

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, November 13, 2009 10:47 AM
  • User1988740161 posted

    That's the hint I needed.  My description and keywords are unique for each ad now.  Thanks!

     

     

     

     

     

    Friday, November 13, 2009 4:34 PM
  • User-1136540166 posted

    in showad.aspx.vb   add these.  The page title will be the title of the ad.  The meta will be the entire ad description.  I would like to make it shorter, but do not know how.   Also, the page title will revert to the site default title as soon as you click one of the photos to view (I do not know why).    I removed the meta tags from my masterpages.  I left a 'default' title in my masterpage and this will overwrite the title, however this will not 'overwrite' the meta tags.


                'to set the page meta from the actual individual ad being shown
                Dim Admeta As New HtmlMeta
                Admeta.Content = ad.Description
                Admeta.Name = ad.Title
                Page.Header.Controls.Add(Admeta)
                'add these two lines to have page title be the title of the ad
    	    AdTypeLabel.Text = OutputFormatting.AdTypeToString(ad.AdType)
                Me.Page.Title = ad.Title + " " + AdTypeLabel.Text + " " + String.Format("{0:c}", ad.Price)



    Saturday, May 22, 2010 4:07 PM
  • User-1136540166 posted

    Setting the length was so obvious, I should not be allowed near a computer for a few days....

    To set a 'reasonable' length of the meta tag,  just change line 3 (in code in my last post) too:

    Admeta.Content = ad.Description.Substring(0, 150)



    Saturday, May 22, 2010 5:20 PM
  • User-1136540166 posted

    To have the webpage title be the title of the ad every time ...   now the title appears always... even after viewing photos. 


    Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
            Me.Page.Title = AdTitleLabel.Text + " " + AdTypeLabel.Text

    Monday, August 9, 2010 1:13 PM