Skip Navigation LinksHome > Categories > Code from a Category

Dynamically changing META Tags with MasterPages (C#)



User Name: codelecturer
Name: Mike Chauhan
Contact Me: www.datawebcoder.com/ContactUs.aspx
Home Page: www.datawebcoder.com
6 years of total IT experience including programming, application development, System Maintenance . 3 years of Experienced and expertise in .Net Framework VB, Visual Basic.Net, ASP.Net 2.0, 3.5 and AD... [More]
Viewed Times: 1147
Add Date: 11/25/2012
How to dynamically change meta tags when using MasterPage in ASP.NET and C#
If you have lots of dynamic pages instead of static, you could be losing out on how your pages are indexed. For example, if you use lots of querystrings, the chances are that all pages (or instances of that page) have the same meta tags (title, description, keywords). To overcome this, we can set up our site so that we can set these meta tags dynamically (upon certain actions). If using a MasterPage, this can get a little trickier, but can still be done. This tutorial shows how.

Firstly, on our MasterPage, we give our meta tags and the page title an ID, and runat attribute:

Next, we put the following code in MasterPage code-behind:


The Default.aspx (content page) looks like the following:

Upon loading of this page, the new Page Title, Description and Keywords meta tags should be displayed. You can check this by viewing the browser window title.

This small area of the page is a content page, the background is the master page.
Then in the code-behind of Default.aspx we have the following, which will set the meta tags:


Happy Programming!!!

Post a Comment

Name: (Optional)
Email: (Optional, you can get an email if somebody replys your comments)*
Email me if somebody respons my comment below:
Details**:
Enter Text
as Below:
(case insensitive, if hard to read, click the "get a new one" button)
 
    
* Your email address will not be shared with any third parties for any reason.
** Maximum 1000 charactors.