Introducing DotNetFunda.com on mobile http://m.dotnetfunda.com ! Be with DotNetFunda.com on the go !
Go to DotNetFunda.com
Twitter TwitterLinkedIn
YouTubeGoogle
 Online : 29965 |  Welcome, Guest!   Register  Login
Home > Articles > ASP.NET > Dynamically writing Meta tags on Master page from a User Control or any other class file

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

Article posted by Raja on 6/21/2007 | Views: 5220 | Category: ASP.NET | Level: Intermediate red flag


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

If you like this article, subscribe to our RSS Feed. You can also subscribe via email to our Interview Questions, Codes and Forums section.

Page copy protected against web site content infringement by Copyscape
Found interesting? Add this to:



Please Sign In to vote for this post.

About Raja Dutta

Experience:5 year(s)
Home page:http://www.dotnetfunda.com
Member since:Monday, June 02, 2008
Level:Starter
Status: [Member]
Biography:
>> Write Response - Respond to this post and get points
Related Posts

In this section we will run through a quick FAQ for WCF. I am sure after reading this you will get a good understanding of the fundamentals of WCF.

In this article we will touch base some important concepts of handling concurrency in LINQ to SQL. We will first see how LINQ supports optimistic concurrency and then we will see what support LINQ provides to handle concurrency violation. We will then touch base on some fine tuning features provided by LINQ at field level and finally we will end this article by discussing two important error reporting options when concurrency conflict happens.

The article discusses one of the new feature introduced with .NET 4.0 which enable you to Redirect your page for Search Engine

This article explains the file upload control.

[B][I]Code Updated on 21st April 2008 to support Sorting, Paging and data manipulation through Stored Procedure in DAL[/I][/B] Almost all of us must have heard about 3-Tier architecture but what is this 4-Tier architecture? What are the benefits and how it is different from other architectures?

More ...
About Us | Contact Us | The Team | Advertise | Software Development | Write for us | Testimonials | Privacy Policy | Terms of Use | Link Exchange | Members | Go Top
General Notice: If you found plagiarised (copied) contents on this page, please let us know the original source along with your correct email id (to communicate) for further action.
Copyright © DotNetFunda.Com. All Rights Reserved. Copying or mimicking the site design and layout is prohibited. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks. | 5/28/2012 11:57:17 AM