Monday, August 31, 2009

set meta tags to master page from Child Page

Meta tag ,title, keywords ,Description and all are very assential on each page , if your using asp.net with Master page then also its possible some people think that how it can be? master page means one page and it get call on each child page creation.but you can also add the keyword , title and all with each pertucular page if you'r using master page then also.

Below are the Steps you need to follow

1-

Create oen Content place holder on your master page with in HEAD section


<head id="Head_Demo" runat="server">
<asp:ContentPlaceHolder runat="server" id="Contentplace_Demo"> </asp:ContentPlaceHolder>
</head >


2 -

on Your Child page put this code :

<asp:Content runat="server" ContentPlaceHolderID="ContentHeaders" ID="Content_Demo" >
<META name="keywords" content="<%=pgKeywords%>">
<TITLE><%=pgTitle%></TITLE>
<META name="description" content="<%=pgDescription%>">
</asp:Content>


3 -

on content page's(Child page) open CodeBehind and Declare this :
Declare variables as below in the global declaration section

Protected pgKeywords As String = ""
Protected pgTitle As String = ""
Protected pgDescription As String = ""


4-
Now set the New title, Desc and all as per the your req. copy that code on page_load Event

pgKeywords = "keywords Content Goes here "
pgTitle = "title Content Goes here"
pgDescription = "Description Content Goes here"

or you can also refer this set mata tags

that's it
hope it will helps you

4 comments:

  1. the problem with this is that you have to add this code to every child page and remember the variables names. What happens if you want to append text or forget to set the title. If you are interested I have an overrides page class that allows for appended title, description and meta data, prevents duplicate tags, and sets a default title based on a predefined value, and can add a canonical tag

    ReplyDelete
  2. wht sort of overrides page class you have plz post some code
    thanx

    ReplyDelete
  3. I cannot post the code on your form so here is a link so you can download it.

    http://docs.google.com/Doc?docid=0ASgYkmErPYM5ZGRqdnA3dHFfNGRjNXpwZGRt&hl=en

    ReplyDelete
  4. thanx Jr_189
    this is also very useful

    ReplyDelete