C#
protected void Page_Load(object sender, EventArgs e)
{
// Change the title
Page.Header.Title = "My Content Page Title";
// Change the background color
Style myStyle = new Style();
myStyle.BackColor = System.Drawing.Color.Red;
Page.Header.StyleSheet.CreateStyleRule(myStyle, null, "html");
// Create Meta Description
HtmlMeta metaDesc = new HtmlMeta();
metaDesc.Name = "DESCRIPTION";
metaDesc.Content = "Content Page Meta Description";
// Create Meta Keywords
HtmlMeta metaKeywords = new HtmlMeta();
metaKeywords.Name = "KEYWORDS";
metaKeywords.Content = "Content Page Meta Keywords";
// Add Meta controls to HtmlHead
HtmlHead head = Page.Header;
head.Controls.Add(metaDesc);
head.Controls.Add(metaKeywords);
}
VB
Private Sub Page_Load()
' Change the title
Page.Header.Title = "My Content Page Title"
' Change the background color
Dim myStyle As New Style()
myStyle.BackColor = System.Drawing.Color.Red
Page.Header.StyleSheet.CreateStyleRule(myStyle, Nothing, "html")
' Create Meta Description
Dim metaDesc As New HtmlMeta()
metaDesc.Name = "DESCRIPTION"
metaDesc.Content = "Content Page Meta Description"
' Create Meta Keywords
Dim metaKeywords As New HtmlMeta()
metaKeywords.Name = "KEYWORDS"
metaKeywords.Content = "Content Page Meta Keywords"
' Add Meta controls to HtmlHead
Dim head As HtmlHead = DirectCast(Page.Header, HtmlHead)
head.Controls.Add(metaDesc)
head.Controls.Add(metaKeywords)
End Sub
This can also be used to override MasterPage setting :)
http://nimishgarg.blogspot.com/2010/02/aspnet-programatically-changing-page.html
The ASP.NET Wiki was started by Scott Hanselman in February of 2008. The idea is that folks spend a lot of time trolling the blogs, googlinglive-searching for answers to common "How To" questions. There's piles of fantastic community-created and MSFT-created content out there, but if it's not found by a search engine and the right combination of keywords, it's often lost.
The ASP.NET Wiki articles moved to CodeProject in October 2013 and will live on, loved, protected and updated by the community.