Go to DotNetFunda.com
 Online : 194 |  Welcome, Guest!   Login
 
Home > Articles > ASP.NET > Dynamically writing Meta tags on Master page from a User Control or any other class file
  • Nominate yourself for FREE online training by Microsoft MVP on OOPS, ASP.NET, ADO.NET and Sql Server.
    Brought to you by DotNetFunda.Com. You can refer to your friends as well !

  • Now you can recommend your article from any website to be selected as "Article of the Day" on DotNetFunda.Com website. If approved, that article will be featured on our home page.

General Notice: If you found copied contents on this page, please let us know the original source along with your correct email id (to communicate) for further action.

Submit Article | Articles Home | Search 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: 2567 | Category: ASP.NET | 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.

Ask all your .NET related questions/clarifications here to get quicker solution.

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

Interesting?   Share and Bookmark this kick it on DotNetKicks.com


About Raja Dutta

Experience:5 year(s)
Home page:http://www.dotnetfunda.com
Member since:Monday, June 02, 2008
Level:Starter
Status: [Member]
Biography:
 Latest post(s) from Raja

   ◘ Forms Authentication in ASP.NET with C#: Advance posted on 9/20/2008 9:58:02 AM
   ◘ Forms Authentication in ASP.NET with C#: Basic posted on 7/30/2008 4:08:34 PM
   ◘ 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


Submit Article


About Us | The Team | Advertise | Contact Us | Feedback | Privacy Policy | 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.
(Best viewed in IE 6.0+ or Firefox 2.0+ at 1024 * 768 or higher)