Welcome to Scribd, the world's digital library. Read, publish, and share books and documents. See more
Download
Standard view
Full view
of .
Look up keyword
Like this
2Activity
0 of .
Results for:
No results containing your search query
P. 1
Master Pages Specifying the Title, Meta Tags, and Other HTML Headers in the Master Page

Master Pages Specifying the Title, Meta Tags, and Other HTML Headers in the Master Page

Ratings:

4.0

(1)
|Views: 638 |Likes:
Published by Ram Sagar Mourya

More info:

Published by: Ram Sagar Mourya on May 28, 2009
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, TXT or read online from Scribd
See more
See less

06/25/2009

pdf

text

original

 
Master Pages :: Specifying the Title, MetaTags, and Other HTML Headers in the MasterPageIntroduction
New master pages created in Visual Studio 2008 have, by default, two ContentPlaceHoldercontrols: one named
head
,
and located in the
<head>
element; and one named
ContentPlaceHolder1
,
placed within the Web Form. The purpose of 
ContentPlaceHolder1
 
is to define a region in the Web Form that can be customized on a page-by-page basis. The
head
 
ContentPlaceHolder enables pages to add custom content to the
<head>
section. (Of course, these two ContentPlaceHolders can be modified or removed, and additionalContentPlaceHolder may be added to the master page. Our master page,
Site.master
,currently has four ContentPlaceHolder controls.)The HTML
<head>
element serves as a repository for information about the web pagedocument that is not part of the document itself. This includes information such as the webpage's title, meta-information used by search engines or internal crawlers, and links toexternal resources, such as RSS feeds, JavaScript, and CSS files. Some of this informationmay be pertinent to all pages in the website. For example, you might want to globallyimport the same CSS rules and JavaScript files for every ASP.NET page. However, there areportions of the
<head>
element that are page-specific. The page title is a prime example.In this tutorial we examine how to define global and page-specific
<head>
section markup inthe master page and in its content pages.
Examining the Master Page's
 
 <head> 
 
Section
 
The default master page file created by Visual Studio 2008 contains the following markup inits
<head>
section:
<head runat="server"><title>Untitled Page</title><asp:ContentPlaceHolder id="head" runat="server"></asp:ContentPlaceHolder></head>
Notice that the
<head>
element contains a
runat="server"
attribute, which indicates that itis a server control (rather than static HTML). All ASP.NET pages derive from the 
class, which is located in the
System.Web.UI
namespace. This class contains a 
that provides access to the page's
<head>
region. Using the
Header
property we can set anASP.NET page's title or add additional markup to the rendered
<head>
section. It is possible,then, to customize a content page's
<head>
element by writing a bit of code in the page's
Page_Load
event handler. We examine how to programmatically set the page's title in Step1.
 
The markup shown in the
<head>
element above also includes a ContentPlaceHolder controlnamed
head
. This ContentPlaceHolder control is not necessary, as content pages can addcustom content to the
<head>
element programmatically. It's useful, however, in situationswhere a content page needs to add static markup to the
<head>
element as the staticmarkup can be added declaratively to the corresponding Content control rather thanprogrammatically.In addition to the
<title>
element and
head
ContentPlaceHolder, the master page's
<head>
 
element should contain any
<head>
-level markup that's common to all pages. In ourwebsite, all pages use the CSS rules defined in the
Styles.css
file. Consequently, weupdated the
<head>
element in the 
 tutorialto include a corresponding
<link>
element. Our
Site.master
master page's current
<head>
 
markup is shown below.
 
<head runat="server"><title>Untitled Page</title><asp:ContentPlaceHolder id="head" runat="server"></asp:ContentPlaceHolder><link href="Styles.css" rel="stylesheet" type="text/css" /></head>
Step 1: Setting a Content Page's Title
The web page's title is specified via the
 
<title>
element. It is important to set each page'stitle to an appropriate value. When visiting a page, its title is displayed in the browser's Titlebar. Additionally, when bookmarking a page, browsers use the page's title as the suggestedname for the bookmark. Also, many search engines show the page's title when displayingsearch results.
Note:
By default, Visual Studio sets the
<title>
element in the master page to"Untitled Page". Similarly, new ASP.NET pages have their
<title>
set to "UntitledPage", too. Because it can be easy to forget to set the page's title to an appropriatevalue, there are many pages on the Internet with the title "Untitled Page". SearchingGoogle for web pages with this title returns roughly 2,460,000 results. EvenMicrosoft is susceptible to publishing web pages with the title "Untitled Page". At thetime of this writing, a Google search reported 236 such web pages in theMicrosoft.com domain.An ASP.NET page can specify its title in one of the following ways:By placing the value directly within the
<title>
elementUsing the
Title
attribute in the
<%@ Page %>
directiveProgrammatically setting the page's
Title
property using code like
Page.Title="
title
"
or
Page.Header.Title="
title
"
.
Content pages don't have a
<title>
element, as it's defined in the master page. Therefore,to set a content page's title you can either use the
<%@ Page %>
directive's
Title
attributeor set it programmatically.
 
Setting the Page's Title Declaratively
A content page's title can be set declaratively through the
 
Title
attribute of the 
.
This property can be set by directly modifying the
<%@ Page %>
directive orthrough the Properties window. Let's look at both approaches.From the Source view, locate the
<%@ Page %>
directive, which is at the top of the page'sdeclarative markup. The
<%@ Page %>
directive for
Default.aspx
follows:
 
<%@ Page Language="VB" MasterPageFile="~/Site.master"AutoEventWireup="false" CodeFile="Default.aspx.vb"Inherits="_Default" Title="Untitled Page" %>
The
<%@ Page %>
directive specifies page-specific attributes used by the ASP.NET enginewhen parsing and compiling the page. This includes its master page file, the location of itscode file, and its title, among other information.By default, when creating a new content page Visual Studio sets the
Title
attribute to"Untitled Page". Change
Default.aspx
's
Title
attribute from "Untitled Page" to "MasterPage Tutorials" and then view the page through a browser. Figure 1 shows the browser'sTitle bar, which reflects the new page title.
Figure 01: The Browser's Title Bar Now Shows "Master Page Tutorials" Instead of "Untitled Page"
The page's title may also be set from the Properties window. From the Properties window,select DOCUMENT from the drop-down list to load the page-level properties, which includesthe
Title
property. Figure 2 shows the Properties window after
Title
has been set to"Master Page Tutorials".

Activity (2)

You've already reviewed this. Edit your review.
1 thousand reads
1 hundred reads

You're Reading a Free Preview

Download
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->