Go to DotNetFunda.com
  Welcome, Guest!  
LoginLogin  
{ Submit resources and get monthly gifts !!! }
Submit: Article | Interview Question | Joke | Question | Link || Search  
 Skip Navigation Links Home > Articles > Dynamically writing Meta tags on Master page from a User Control or any other class file

All Articles | Post Articles

Dynamically writing Meta tags on Master page from a User Control or any other class file

 Posted on: 6/21/2007 2:29:26 PM by Raja | Views: 1171 | Category: ASP.NET 2.0 | Level: Intermediate | Print Article

While developing web sites, you must have came across situations where you need to write Meta tags from the user control or any class files.

At first look it seems very difficult but I think it is not that much.

 
In My example I am writing Meta contents of my page from a utility class file.

Lets say my following method is in utility.cs file

// method that will write meta tags for keyword and description.

- Hide Code
 public static void WriteMetaTags(Control ctrl, string keyword, string desc)

{

Page pge = (Page)ctrl;

HtmlMeta mKey = new HtmlMeta();
mKey.Name = "keyword";
mKey.Content = key;
pge.Header.Controls.Add(mKey);

HtmlMeta mDesc = new HtmlMeta();
mDesc.Name = "description";
mDesc.Content = desc;
pge.Header.Controls.Add(mDesc);

}


I need to call this method from my .aspx page like this.
utility.WriteMetaTags(this, keyword, desc) and its done.

You can also call this method from a user control like
utility.WriteMetaTags(this.parent, keyword, desc)

Enjoy!!!
Bookmark and Share

About Raja Dutta

Experience:3 year(s)
Home page:
Member since:Monday, June 02, 2008
Biography:--
Raja
 Latest post(s) from Raja

   ◘ Getting selected value from asp:RadioButtonList in JavaScript posted on 4/15/2008 4:03:49 AM
   ◘ Reading appSettings and connectionStrings from web.config file in asp.net posted on 10/9/2007 7:14:12 PM
   ◘ Generating Ms Word document in ASP.NET and C# posted on 9/11/2007 4:49:45 PM
   ◘ Dynamically writing Meta tags on Master page from a User Control or any other class file posted on 6/21/2007 2:29:26 PM
   ◘ How to implement Remoting in ASP.NET posted on 6/21/2007 1:09:49 PM



Question: Why to use www.dotnetfunda.com google search?
Answer: This search has been especially optimized to search technical articles. You may find to-the-point results in comparison with other search.
Google
About Us | Contact Us | Terms of Use | Link Exchange | Members | Go Top
All rights reserved to DotNetFunda.com. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks.