C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Tips » Web Development »

Changing Meta tags dynamically


Posted Date: 30 Oct 2009    Resource Type: Tips    Category: Web Development
Author: NishaMember Level: Bronze    
Rating: 1 out of 5Points: 3



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

This is the Default Page Title...



Next get/set properties in code behind:


public string MetaTitle
{
get
{
return PageTitle.Text;
}
set
{
PageTitle.Text = value;
}
}
public string MetaKeywords
{
get
{
return PageKeywords.Content;
}
set
{
PageKeywords.Content = value;
}
}
public string MetaDescription
{
get
{
return PageDescription.Content;
}
set
{
PageDescription.Content = value;
}
}



The .cs of a Default.aspx page whose meta tag has to be changed is :


using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
MasterPage myMaster = (MasterPage)this.Master;
myMaster.MetaTitle = "This is the new Page Title, which is set upon Page_Load";
myMaster.MetaDescription = "This is the new Page Description, which is set upon Page_Load";
myMaster.MetaKeywords = "new, page, keywords, set, upon, page, load";
}
}



Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
Meta tag  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Achieve checking multiple selections and batch deletions in row input report
Previous Resource: Commonly used reguler expressions
Return to Discussion Resource Index
Post New Resource
Category: Web Development


Post resources and earn money!
 
More Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use