Hello There,
if you are trying to set a content page description, you can do something like this.
First we create a master page called MetaTagsDynamically.master
<%
@ Master Language="C#" AutoEventWireup="true" CodeFile="MetaTagsDynamically.master.cs" Inherits="common_MetaTagsDynamically" %><!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" id="mainHead"> ----- here we are giving a id to the head tag
<title>Meta Tags Dynamically</title><meta name="DESCRIPTION" content="This is the master page description " /> this is description for master page
</
head>
<
body>
<form id="form1" runat="server">
<div>
<asp:contentplaceholder id="cpMain" runat="server"></asp:contentplaceholder>
</div></form>
</
body>
</
html>
Now the content page called DynamicPageDesc.aspx
<%
@ Page Language="C#" MasterPageFile="~/common/MetaTagsDynamically.master" AutoEventWireup="true" CodeFile="DynamicPageDesc.aspx.cs" Inherits="General_DynamicPageDesc" Title="Dynamic Page Description" %>
<
asp:Content ID="Content1" ContentPlaceHolderID="cpMain" Runat="Server"></asp:Content>
In CODE BEHIND OF DynamicPageDesc.aspx , i am adding the page descripiton on the page_load event
protected void Page_Load(object sender, EventArgs e)
{
//First we find the Head Tag in Master Page
HtmlHead headMain = (HtmlHead)Page.Master.FindControl("mainHead");
HtmlMeta htMeta = new HtmlMeta();
htMeta.Attributes.Add("name", "description");
htMeta.Attributes.Add("content", "here you can type page description");
//adding Meta Tag to Head
headMain.Controls.Add(htMeta);
//Similiarly we can add keyword Meta Tag to Head Section
HtmlMeta htMeta1 = new HtmlMeta();
htMeta1.Attributes.Add("name", "keywords");
htMeta1.Attributes.Add("content", "Here you can type page keywords");
// adding the Meta Tag to Head
headMain.Controls.Add(htMeta1);
}
now if you run the page and view source, this is what you will get
<!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 id="ctl00_mainHead"><title>
Dynamic Page Description
</title><meta name="DESCRIPTION" content="This is the master page description " /> ---------- coming from the master page
<meta name="description" content="here you can type page description" />
<meta name="keywords" content="Here you can type page keywords" />------------------------coming from the content page
</head>
<body>
<form name="aspnetForm" method="post" action="DynamicPageDesc.aspx" id="aspnetForm">
<div>
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwULLTEwMDUyNjYzMjhkZNFkZUOSU4P6hz2M5dCGdXutqn7l" />
</div>
<div>
</div>
</form>
</body>
</html>
Hope this helps
Thanks
Keyboard not found. Please Press < F1 > to RESUME
Please Remember to Mark as Answer for the post(s) that help you.....so it can help others......Thanks