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 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


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%>">
<META name="description" content="<%=pgDescription%>">

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 = ""

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


  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

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

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

  4. thanx Jr_189
    this is also very useful