Vous êtes sur la page 1sur 13

By: Adnan Amin (Lecturer/Software Programmer) 1

Lesson: 08
Topic: Master & Contents Pages

WEB ENGINEERING-II
USING ASP.NET
By
Adnan Amin
Lecturer / Software Programmer
Information and Communication Technology
(ICT Dept)
By: Adnan Amin (Lecturer/Software Programmer) 2

Overview
• Master Page
• ContentPlaceHolder HTML Server Control.
• Contents pages
By: Adnan Amin (Lecturer/Software Programmer) 3

New Pages in ASP.net


• There are two New pages introduced in ASP.net:
• Master page
• Content Page
By: Adnan Amin (Lecturer/Software Programmer) 4

The Master page

• Master page is provides the page template


for the whole web site.
• It can contain one or more layout contents.
• It can place code in master pages of the
contents pages.
• Contents pages take place in placeholder
location of the master page which will
defined by ContentPlaceHolder controls.
• The extension of master page is *.master.
By: Adnan Amin (Lecturer/Software Programmer) 5

2. Content page

• The content page provides particular


contents.
• At run time, the contents will be displayed
within ContentPlaceHolder controls.
• Each content page must be linked with a
specific master page.
• The master page layout will display
surrounding the content page.
By: Adnan Amin (Lecturer/Software Programmer) 6

Adding New Master Page


• Open new website.
• Add new Item  select Master Page
• Design the master page.
By: Adnan Amin (Lecturer/Software Programmer) 7

Creating a Content Page


• Add New Item  Select web form and click Add button.
• Select the MasterPage for your Content page.

• At top of the page code, you will see: (if not then type)

<%@ Page Language="VB"


AutoEventWireup="false"
CodeFile="Default2.aspx.vb" Inherits="Default2"
MasterPageFile="~/MasterPage.master" %>
By: Adnan Amin (Lecturer/Software Programmer) 8
Converting a normal page to content
page
• Follow the following steps:
1. Content page cannot contain any normal “page” markup.
1. No html tag (<html>, <body>,<head><title>etc)
2. Generally contain only Content Controls.
1. Generally contain only Content controls
(ContentPlaceHolder Control) associated with master
page.
3. Master page used the ContentPlaceHolderID property to
determine where the content goes.
4. Add Content control and type or insert the contents.
<asp:Content ContentPlaceHolderID="ContentPlaceHolder1“
runat="server">
Type the content of the page.
</asp:Content>
5. Remove “page” elements and stuff.
By: Adnan Amin (Lecturer/Software Programmer) 9

Adding/Override Default Content


(On Master Page)
• We can also add more than one
ContentPlaceHolder controls on master page.
• Content page also need not to supply all the
content of the master page. So we can override
the contents of master page in content page.
By: Adnan Amin (Lecturer/Software Programmer) 10

Adding Default Content

• Open the Master page


• Add ContentPlaceHolder Control from ToolBox on
Master page.
• Add some master page Stuff in
ContentPlaceHolder (above one)
• Run the content pages where the master page is
used.
• Definitely you will get more information on content
pages by adding second default content on
master page.
By: Adnan Amin (Lecturer/Software Programmer) 11

Override the Default contents


• If we don’t need the default contents of master
page on some of the content pages then we can
override it.
• Open the Content page and right click on
ContentPlaceHolder control  then click on
“Create Custom Contents”.  bring changes in
source code.
• If you need back the default contents then again
right on ContentPlaceHolder  then click on
“Move to Default Mater’s content” option from the
menu in design of view of content page.
By: Adnan Amin (Lecturer/Software Programmer) 12

Best Practice Creating Master Pages.

• Usually developers use the tables to design


the layout for the master pages.
• You can also use CSS positioning to get
the same effect.
• Or Place header , footer, navigation in table
cells.
By: Adnan Amin (Lecturer/Software Programmer) 13

Assignment: Create the following


layout.
ADD HERE “header”

Menu 1 News
Update
Menu 2

Menu 3

Menu 4

Image

Add HERE “Footer”

Vous aimerez peut-être aussi