How do I add a title and metta keywords/descript to dynamic page

Last post 09-02-2008 9:23 PM by 101jonny. 9 replies.

Sort Posts:

  • How do I add a title and metta keywords/descript to dynamic page

    08-29-2008, 6:18 PM
    • Member
      74 point Member
    • 101jonny
    • Member since 05-11-2008, 3:54 AM
    • Minnesota
    • Posts 132

    Hi all~

    How do I add a title and metta keywords/descript to dynamic page I am using 2.0 vb

    any input will be apreciated

     

    Jonny

  • Re: How do I add a title and metta keywords/descript to dynamic page

    08-30-2008, 4:40 AM
    Answer
    • Member
      185 point Member
    • Audley9
    • Member since 05-22-2007, 12:35 AM
    • Posts 152

    101jonny:

    Hi all~

    How do I add a title and metta keywords/descript to dynamic page I am using 2.0 vb

    any input will be apreciated

     

    Jonny

    Please see the following post

    http://forums.asp.net/p/1274723/2420196.aspx#2420196

  • Re: How do I add a title and metta keywords/descript to dynamic page

    08-31-2008, 11:32 PM
    • Member
      74 point Member
    • 101jonny
    • Member since 05-11-2008, 3:54 AM
    • Minnesota
    • Posts 132

    Do you have a working example?

    Cant figure out your code of the other guys code~

    ~J

  • Re: How do I add a title and metta keywords/descript to dynamic page

    09-01-2008, 1:14 AM
    Answer
    • Contributor
      4,221 point Contributor
    • Coool
    • Member since 04-11-2007, 5:24 AM
    • Ahmedabad, India
    • Posts 652

    Hi 101jonny,

    you can achieve this using Literal control. Just add 2 Literal Control in the Head for Title and Meta tag and in page_Load set the Text Property of Literal Control.

    Like...

    <Head id="Head1" runat="server">

    <title><asp:Literal id="ltrTitle" runat="server"></title>

    <asp:Literal id="ltrMeta" runat="server">

    </Head>

     In page_Load

    ltrTitle.Text = "My Website";

    ltrMeta.Text = "<meta ...";

    I hope this will help u.

    Please mark as Answer if it helps u. Thanks!

    Parth Patel
    Techsture Technologies
    Software Developer
    Ahmedabad
  • Re: How do I add a title and metta keywords/descript to dynamic page

    09-01-2008, 3:48 AM
    • Member
      74 point Member
    • 101jonny
    • Member since 05-11-2008, 3:54 AM
    • Minnesota
    • Posts 132

    I recieved errors Heres my Code

    Partial Class MasterPage

    Inherits System.Web.UI.MasterPage

    Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)

    ltrTitle.Text = "Anything";

    ltrMeta.Text = "<meta name="description" content="Microsoft portal site for the ASP.NET development community. Download Visual Web Developer, post to the forums, read ASP.net blogs and learn about ASP.net." />

    &

    <meta name="keywords" content="ASP.NET, ASP.NET 2.0, Whidbey, .aspx, .ascx, Web, HTML, Developer, Internet, Microsoft, Web Services, Visual Studio .NET" />"

    End Sub

    'Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    'End Sub

    End Class

     

     

    and in my MASTER PAGE -------------------------------------->

    <%@ Master Language="VB" CodeFile="MasterPage.master.vb" Inherits="MasterPage" %>

    <%@ Register Src="rightnav.ascx" TagName="rightnav" TagPrefix="uc4" %>

    <%@ Register Src="header.ascx" TagName="header" TagPrefix="uc3" %>

    <%@ Register Src="footer.ascx" TagName="footer" TagPrefix="uc2" %>

    <%@ Register Src="leftNav.ascx" TagName="leftNav" TagPrefix="uc1" %>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml" >

    <head runat="server">

    <link rel="shortcut icon" href="favicon.ico" type="image/vnd.microsoft.icon" />

    <link rel="icon" href="favicon.ico" type="image/x-icon" />

     

    <title><asp:Literal id="ltrTitle" runat="server"></title>

    <asp:Literal id="ltrMeta" runat="server">

     

     

     

    </
    head>

    <body style="font-family:Verdana;font-size:12px;">

    <form id="form1" runat="server">

     

    <div>

     

     

     

     

     

  • Re: How do I add a title and metta keywords/descript to dynamic page

    09-01-2008, 4:41 AM
    • Contributor
      4,221 point Contributor
    • Coool
    • Member since 04-11-2007, 5:24 AM
    • Ahmedabad, India
    • Posts 652

    Hi 101jonny,

    If you are getting compile time error then its obvious.

    If you want to add double quote in Literal Text then u have to repeat double quote twice in value. e.g..

    ltrMeta.Text  = "<meta name=""disccription"" ...";

    will print

    <meta name="discription" ..

    Please mark as Answer if it helps u. Thanks!

    Parth Patel
    Techsture Technologies
    Software Developer
    Ahmedabad
  • Re: How do I add a title and metta keywords/descript to dynamic page

    09-01-2008, 8:30 PM
    • Member
      74 point Member
    • 101jonny
    • Member since 05-11-2008, 3:54 AM
    • Minnesota
    • Posts 132

    Is this code the same if being used with a master page?

    ~Jonny

  • Re: How do I add a title and metta keywords/descript to dynamic page

    09-02-2008, 5:21 PM
    • Member
      185 point Member
    • Audley9
    • Member since 05-22-2007, 12:35 AM
    • Posts 152

    I am confused!  Do you want want every page to have the same meta?  This is the only reason I can see puting the meta at the master page level.  You have lots of options to do this, hard code it in the head section of the head section of your materpage

    1    <head>
    2    <title>Your title herr</title>
    3    <meta name="description" content="Blah Blah Blah"/>
    4    <meta name="keyword" content="Blah Blah Blah"/>
    5    </head>

     Or you can choose to use any of the other methods posted.

    Most page developers perfer each individual page to have it own unique title, and meta tags as it will get better search engine results.   I perfer with dynamically constructed pages to use

    1    Dim metaKey As HtmlMeta = New HtmlMeta()
    2    Dim Metadesc As HtmlMeta = New HtmlMeta()
    3    Dim head As HtmlHead = CType(Page.Header, HtmlHead)
    4        
    5    metaKey.Name = "keywords"
    6    metaKey.Content = "You list of Keywords"
    7    Mtadesc.Name = "description"
    8    Metadesc.Content = "Your description of your page contents"
    9    head.Controls.AddAt(1, metaKey)
    10   head.Controls.AddAt(2, Metadesc)
    11   
    12   
    

      You can the do thing like attach an ID and a runat="server" to a "p" tag. and then use the text inside your "p" tag as you contents for your description.  For example if you used "FirstP" as the ID for a paragraph with a runat="server" you can do this: 

    1    Dim metaString as String = FirstP.InnerHtml
    2    Metadesc.Content = metaString
    

     This type of method is very usefull if you are work with contents from a database.  You can use the data from queries to build keywords on description text on the fly.

    Regards

  • Re: How do I add a title and metta keywords/descript to dynamic page

    09-02-2008, 5:54 PM
    • Member
      231 point Member
    • tolgahan
    • Member since 01-19-2008, 4:30 AM
    • Posts 65

    in your asp.net page (ex: default.aspx)

    <head runat="server">
        <title>Untitled Page</title>
        <meta runat="server" id="metaDescription" name="description" content="" />
        <meta runat="server" id="metaKeywords" name="keywords" content="" />
    </head>

    in your code page (ex: default.aspx.cs)

        protected void Page_Load(object sender, EventArgs e)
        {
            //Setting Title
            Page.Title = "New Title";
            //Setting Description Meta Tag
            metaDescription.Content = "This is as page about bla bla..";
            //Setting Keywords Meta Tag
            metaKeywords.Content = "Bla, Page, Aloha, Oha, Brrrr";
        }
    

      

    Good Luck!

    Tolgahan ALBAYRAK
  • Re: How do I add a title and metta keywords/descript to dynamic page

    09-02-2008, 9:23 PM
    • Member
      74 point Member
    • 101jonny
    • Member since 05-11-2008, 3:54 AM
    • Minnesota
    • Posts 132
    Compiler Error Message: CS0103: The name 'metaDescription' does not exist in the current context

    Recieved this eror when trying to test on localhost, there should be nothing wrong with using it in a masterpage should there?

     

    ~Jonny

Page 1 of 1 (10 items)