dotnetspider.com
Login Login    Register      

TutorialsForumCareer DevelopmentResourcesReviewsJobsInterviewCommunitiesProjectsTraining

Subscribe to Subscribers
Talk to Webmaster
Tony John

Facebook
Google+
Twitter
LinkedIn
Online MembersAbul Bashar Sardar
More...
Join our online Google+ community for Bloggers, Content Writers and Webmasters




Resources » Code Snippets » C# Syntax

How to dynamically change meta tags when using MasterPage in ASP.NET and C#


Posted Date:     Category: C# Syntax    
Author: Member Level: Silver    Points: 10



 


Someone asked me yesterday about - how to dynamically change meta tags when using MasterPage in ASP.NET and C#. Lots of beginners are searching for a solution all over the internet but some articles are difficult to understand for them. So this one is intended for beginners.

When you have lots of dynamic pages instead of static, you may want to change the Meta Keywords dynamically which is helpful in SEO (Search Engine Optimization).

The solution to this is to first provide an id to your Head Tag in Master Page :


<head runat="server" id="mainHead">


Now in the page where you want to change the Meta tags dynamically add the following code sample on the page load event :


//Find the Head Tag in Master Page
HtmlHead hdMain = (HtmlHead)Page.Master.FindControl("mainHead");
HtmlMeta htmMeta = new HtmlMeta();
htmMeta.Attributes.Add("name","description");
htmMeta.Attributes.Add("content", "This is content");
//Add Meta Tag to Head

hdMain.Controls.Add(htmMeta);

//Adding keyword Meta Tag to Head Section
HtmlMeta hm2 = new HtmlMeta();
hm2.Attributes.Add("name", "keywords");
hm2.Attributes.Add("content", "Here you can pass your keywords");
hdMain.Controls.Add(hm2);


And that’s it! Now view the page source and you will find the description and keyword tags there.

Reference http://kaniks.blog.co.in/2008/08/05/how-to-dynamically-change-meta-tags-when-using-masterpage-in-aspnet-and-c/





Did you like this resource? Share it with your friends and show your love!


Responses to "How to dynamically change meta tags when using MasterPage in ASP.NET and C#"

No responses found. Be the first to respond...

Feedbacks      

Post Comment:




  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:   Sign In to fill automatically.
    Email: (Will not be published, but required to validate comment)



    Type the numbers and letters shown on the left.


    Next Resource: Paypal website payment pro in c#
    Previous Resource: Export DataSet to Word files in ASP.NET with C#
    Return to Resources
    Post New Resource
    Category: C# Syntax


    Post resources and earn money!
     
    More Resources
    Popular Tags   Tag posting guidelines   Search Tags  
    Dynamically change Meta Tag using C  .  Dynamically change Meta Tag using ASP.NET  .  



    Follow us on Twitter: https://twitter.com/dotnetspider

    Active Members
    TodayLast 7 Daysmore...

    Awards & Gifts
    Email subscription
  • .NET Jobs
  • .NET Articles
  • .NET Forums
  • Articles Rss Feeds
    Forum Rss Feeds


    About Us    Contact Us    Copyright    Privacy Policy    Terms Of Use    Revenue Sharing sites   Advertise   Talk to Tony John
    Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India
    2005 - 2012 All Rights Reserved.
    .NET and other trademarks mentioned in this site belong to Microsoft and other respective trademark owners.
    Articles, tutorials and all other content offered here is for educational purpose only.
    We are not associated with Microsoft or its partners.