AspAlliance.com LogoASPAlliance: Articles, reviews, and samples for .NET Developers
URL:
http://aspalliance.com/articleViewer.aspx?aId=411&pId=-1
Setting the ASP.NET Page Title and Meta Tags
page
by Chris Garrett
Feedback
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 20622/ 41

Setting the ASP.NET Page Title and Meta Tags

When you first look at using ASP.NET it seems that the only page objects you have access to are the ones within the FORM tags. Actually with a tiny amount of work you can set other page properties.

The two types of information are set slightly differently. The TITLE is basically a literal tag and it's value is whatever is put between the starting and ending tags.

Meta tags have their values set as attributes, so these need to be set with another approach.

The example script shows what we need to do in action. It allows the user to enter some text which resets the page title.

See it in action
/chrisg/tools/settitle.aspx

If you now take a look at the source we will see both pieces of work that need to be done.

First, in the ASPX file we need to set IDs and RUNAT attributes for each of the items we want to control.

In the codebehind file we first declare new controls for each of the items. We create them as HTMLGenericControls which seems to work fine.

To set the values we use InnerText for the Title, which sets the text that appears between its opening and closing tags, and we set the "content" attribute value for the two Meta tags.

View Source
/chrisg/tools/view-settitle.aspx.asp

/chrisg/tools/view-settitle.vb.asp

Download
/chrisg/tools/download.asp?file=settitle.aspx

/chrisg/tools/download.asp?file=settitle.vb

This is a simple demonstration, but it answers a question I get asked a fair amount. Using this, a content database and other techniques it is possible to create a workable central control for all search engine related site-tweaking :O)


Product Spotlight
Product Spotlight 

©Copyright 1998-2024 ASPAlliance.com  |  Page Processed at 2024-04-26 1:50:15 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search