SlideShare a Scribd company logo
Master Page
Master page allows you to create a consistent look and behaviour
for all the pages in your web applications . Master Page Design is
common for all the pages. Master page actually consists of two
pieces, the master page itself and one or more content pages..
A master page is an ASP.NET file with the extension .master.
ContentPlaceholder control, which defines a region on the master
page, is where the content pages can plug in page specific content.
 A Master Page enables user to share the same content among
multiple content pages in a website.
ASP.NET master pages allow user to create a consistent layout for
the pages in a application.
When users request the content pages, they merge with the master
page to produce output that combines the layout of the master page
with the content from the content page.
Master Page
 Master pages in ASP.NET Web Forms start with the @Masterdirective .
 The directive looks like the following.
<%@MasterLanguage="C#“CodeFile="MasterPage.master.cs"
Inherits="MasterPage" %>
 @Page directive that is used for ordinary .aspx pages.
 The directive looks like the following.
<%@PageLanguage="C#”
MasterPageFile="~/MasterPages/Master1.master"Title="Content
Page"%>
 To enable pages to insert content, the master page contains a placeholder
tag <asp:ContentPlaceHolder> for individual content.
Working with Master Page
1. To use master pages, first create a master page and add
tables and other common elements.
2. Add <ContentPlaceHolder> controls to the master page
from toolbox.
3. To create the content pages, add standard Web forms,
select the master page check box when creating the
page and then select the master page.
4. Add content to the page.
Creating a Master Page
 Step 1
Create new project in Visual Studio 2010
1. Go to File-> New-> Web Site-> Visual C#->ASP.NET
Website-> Entry Application Name-> OK
2. Create a new web site named MasterPageDemo.
3. Right click on website in Solution Explorer and Click
on Add New Item from pop up menu.
Creating Master Page
4. Add Master Page to the application named
“ MasterPage.master” and create design.
Source Code
Creating Master Page
Design
Creating Master Page
Step 2
5. In Solution Explorer, right click on website and click
on Add New Item and select web form from pop-up
window.
6. Change the name of the web form and select the check
box of Select Master Page then click on Add button.
Creating Master Page
7. Select the Masterpage.master and click on OK.
Creating Master Page
8. In content Page Index.aspx, user can use the content
place holder to add content to the page.
Add
Content
Here
Dynamically Loading Master Page
 Websites uses different master pages dynamically with
a content page depending upon the request.
 This features enables the users to customize the
appearance of the website by loading different master
pages. A menu of master pages allow our users to pick
their favourite layout.
Steps to create dynamically loading master page as
following:
1. Create two Master Page MasterPage2.master and
MasterPage3.master with one ContentPlaceHolder
in each.
MasterPage2.master
Source Code Design
MasterPage3.master
Source Code Design
2. Create a content page “DefaultPage4.aspx” using
MasterPage2.page as default master page.
3. User can switch between master pages using links on
the web page.
Advantages of Master Page
 They allow user to centralize the common functionality of
user pages so that user can make updates in just one
place.
 They make it easy to create one set of controls and code
and apply the results to a set of pages. For example, user
can use controls on the master page to create a menu that
applies to all pages.
 They give user fine-grained control over the lausert of the
final page by allowing user to control how the placeholder
controls are rendered.
 They provide an object model that allows user to
customize the master page from individual content pages.
Thank You

More Related Content

What's hot

JavaScript - Chapter 12 - Document Object Model
  JavaScript - Chapter 12 - Document Object Model  JavaScript - Chapter 12 - Document Object Model
JavaScript - Chapter 12 - Document Object Model
WebStackAcademy
 
ASP.NET State management
ASP.NET State managementASP.NET State management
ASP.NET State management
Shivanand Arur
 
jQuery
jQueryjQuery
ASP.NET Web API
ASP.NET Web APIASP.NET Web API
ASP.NET Web APIhabib_786
 
Php and MySQL
Php and MySQLPhp and MySQL
Php and MySQL
Tiji Thomas
 
JavaScript - Chapter 6 - Basic Functions
 JavaScript - Chapter 6 - Basic Functions JavaScript - Chapter 6 - Basic Functions
JavaScript - Chapter 6 - Basic Functions
WebStackAcademy
 
Controls
ControlsControls
Controls
teach4uin
 
Servlets
ServletsServlets
Servlets
ZainabNoorGul
 
Android share preferences
Android share preferencesAndroid share preferences
Android share preferences
Ajay Panchal
 
Php with MYSQL Database
Php with MYSQL DatabasePhp with MYSQL Database
Php with MYSQL Database
Computer Hardware & Trouble shooting
 
Web controls
Web controlsWeb controls
Web controls
Sarthak Varshney
 
JQuery introduction
JQuery introductionJQuery introduction
JQuery introduction
NexThoughts Technologies
 
Javascript operators
Javascript operatorsJavascript operators
Javascript operatorsMohit Rana
 
Java Server Pages
Java Server PagesJava Server Pages
Java Server Pages
Kasun Madusanke
 
Ajax ppt
Ajax pptAjax ppt
JavaScript - Chapter 11 - Events
 JavaScript - Chapter 11 - Events  JavaScript - Chapter 11 - Events
JavaScript - Chapter 11 - Events
WebStackAcademy
 
Server Controls of ASP.Net
Server Controls of ASP.NetServer Controls of ASP.Net
Server Controls of ASP.Net
Hitesh Santani
 
PHP - Introduction to PHP AJAX
PHP -  Introduction to PHP AJAXPHP -  Introduction to PHP AJAX
PHP - Introduction to PHP AJAX
Vibrant Technologies & Computers
 

What's hot (20)

GRID VIEW PPT
GRID VIEW PPTGRID VIEW PPT
GRID VIEW PPT
 
Js ppt
Js pptJs ppt
Js ppt
 
JavaScript - Chapter 12 - Document Object Model
  JavaScript - Chapter 12 - Document Object Model  JavaScript - Chapter 12 - Document Object Model
JavaScript - Chapter 12 - Document Object Model
 
ASP.NET State management
ASP.NET State managementASP.NET State management
ASP.NET State management
 
jQuery
jQueryjQuery
jQuery
 
ASP.NET Web API
ASP.NET Web APIASP.NET Web API
ASP.NET Web API
 
Php and MySQL
Php and MySQLPhp and MySQL
Php and MySQL
 
JavaScript - Chapter 6 - Basic Functions
 JavaScript - Chapter 6 - Basic Functions JavaScript - Chapter 6 - Basic Functions
JavaScript - Chapter 6 - Basic Functions
 
Controls
ControlsControls
Controls
 
Servlets
ServletsServlets
Servlets
 
Android share preferences
Android share preferencesAndroid share preferences
Android share preferences
 
Php with MYSQL Database
Php with MYSQL DatabasePhp with MYSQL Database
Php with MYSQL Database
 
Web controls
Web controlsWeb controls
Web controls
 
JQuery introduction
JQuery introductionJQuery introduction
JQuery introduction
 
Javascript operators
Javascript operatorsJavascript operators
Javascript operators
 
Java Server Pages
Java Server PagesJava Server Pages
Java Server Pages
 
Ajax ppt
Ajax pptAjax ppt
Ajax ppt
 
JavaScript - Chapter 11 - Events
 JavaScript - Chapter 11 - Events  JavaScript - Chapter 11 - Events
JavaScript - Chapter 11 - Events
 
Server Controls of ASP.Net
Server Controls of ASP.NetServer Controls of ASP.Net
Server Controls of ASP.Net
 
PHP - Introduction to PHP AJAX
PHP -  Introduction to PHP AJAXPHP -  Introduction to PHP AJAX
PHP - Introduction to PHP AJAX
 

Similar to Master page in Asp.net

Aspnet master pages_tutorial_10_cs
Aspnet master pages_tutorial_10_csAspnet master pages_tutorial_10_cs
Aspnet master pages_tutorial_10_csVaibhav Chavan
 
masterpages 1.pptx
masterpages 1.pptxmasterpages 1.pptx
masterpages 1.pptx
SANJUSANJEEVTOPPO
 
04 asp.net session05
04 asp.net session0504 asp.net session05
04 asp.net session05
Vivek chan
 
04 asp.net session05
04 asp.net session0504 asp.net session05
04 asp.net session05Mani Chaubey
 
Advanced SharePoint 2013 Site Administration
Advanced SharePoint 2013 Site AdministrationAdvanced SharePoint 2013 Site Administration
Advanced SharePoint 2013 Site Administration
Learning SharePoint
 
Chapter 12
Chapter 12Chapter 12
Master Pages In Asp.net
Master Pages In Asp.netMaster Pages In Asp.net
Master Pages In Asp.net
parallelminder
 
11 asp.net session16
11 asp.net session1611 asp.net session16
11 asp.net session16
Vivek chan
 
Creating Web Pages with Microsoft FrontPage - R.D.Sivakumar
Creating Web Pages with Microsoft FrontPage - R.D.SivakumarCreating Web Pages with Microsoft FrontPage - R.D.Sivakumar
Creating Web Pages with Microsoft FrontPage - R.D.Sivakumar
Sivakumar R D .
 
ASP.NET 06 - Customizing Your Sites Appearance
ASP.NET 06 - Customizing Your Sites AppearanceASP.NET 06 - Customizing Your Sites Appearance
ASP.NET 06 - Customizing Your Sites Appearance
Randy Connolly
 
15 asp.net session22
15 asp.net session2215 asp.net session22
15 asp.net session22
Vivek chan
 
04 asp.net session05
04 asp.net session0504 asp.net session05
04 asp.net session05Niit Care
 
Net4’s EasySite Builder Step By Step Guide to Create Business Website
Net4’s EasySite Builder Step By Step Guide to Create Business WebsiteNet4’s EasySite Builder Step By Step Guide to Create Business Website
Net4’s EasySite Builder Step By Step Guide to Create Business Website
Net4 India Ltd.
 
Net4’s EasySite Builder Step by Step Guide
Net4’s EasySite Builder Step by Step GuideNet4’s EasySite Builder Step by Step Guide
Net4’s EasySite Builder Step by Step Guide
Pallavi Vyas
 
Chapter 5 (master page)
Chapter 5 (master page)Chapter 5 (master page)
Chapter 5 (master page)
let's go to study
 
BP304 - Blog It Up, Baby! Extending the new IBM Lotus Domino Blog Template
BP304 - Blog It Up, Baby! Extending the new IBM Lotus Domino Blog TemplateBP304 - Blog It Up, Baby! Extending the new IBM Lotus Domino Blog Template
BP304 - Blog It Up, Baby! Extending the new IBM Lotus Domino Blog Template
Sean Burgess
 
.NET 1.1 Base Page Framework Article
.NET 1.1 Base Page Framework Article.NET 1.1 Base Page Framework Article
.NET 1.1 Base Page Framework Article
bitburner93
 
ASP.NET Lecture 3
ASP.NET Lecture 3ASP.NET Lecture 3
ASP.NET Lecture 3
Julie Iskander
 

Similar to Master page in Asp.net (20)

Aspnet master pages_tutorial_10_cs
Aspnet master pages_tutorial_10_csAspnet master pages_tutorial_10_cs
Aspnet master pages_tutorial_10_cs
 
Master pages
Master pagesMaster pages
Master pages
 
masterpages 1.pptx
masterpages 1.pptxmasterpages 1.pptx
masterpages 1.pptx
 
04 asp.net session05
04 asp.net session0504 asp.net session05
04 asp.net session05
 
04 asp.net session05
04 asp.net session0504 asp.net session05
04 asp.net session05
 
Advanced SharePoint 2013 Site Administration
Advanced SharePoint 2013 Site AdministrationAdvanced SharePoint 2013 Site Administration
Advanced SharePoint 2013 Site Administration
 
Chapter 12
Chapter 12Chapter 12
Chapter 12
 
Master Pages In Asp.net
Master Pages In Asp.netMaster Pages In Asp.net
Master Pages In Asp.net
 
11 asp.net session16
11 asp.net session1611 asp.net session16
11 asp.net session16
 
Creating Web Pages with Microsoft FrontPage - R.D.Sivakumar
Creating Web Pages with Microsoft FrontPage - R.D.SivakumarCreating Web Pages with Microsoft FrontPage - R.D.Sivakumar
Creating Web Pages with Microsoft FrontPage - R.D.Sivakumar
 
ASP.NET 06 - Customizing Your Sites Appearance
ASP.NET 06 - Customizing Your Sites AppearanceASP.NET 06 - Customizing Your Sites Appearance
ASP.NET 06 - Customizing Your Sites Appearance
 
15 asp.net session22
15 asp.net session2215 asp.net session22
15 asp.net session22
 
Master page
Master pageMaster page
Master page
 
04 asp.net session05
04 asp.net session0504 asp.net session05
04 asp.net session05
 
Net4’s EasySite Builder Step By Step Guide to Create Business Website
Net4’s EasySite Builder Step By Step Guide to Create Business WebsiteNet4’s EasySite Builder Step By Step Guide to Create Business Website
Net4’s EasySite Builder Step By Step Guide to Create Business Website
 
Net4’s EasySite Builder Step by Step Guide
Net4’s EasySite Builder Step by Step GuideNet4’s EasySite Builder Step by Step Guide
Net4’s EasySite Builder Step by Step Guide
 
Chapter 5 (master page)
Chapter 5 (master page)Chapter 5 (master page)
Chapter 5 (master page)
 
BP304 - Blog It Up, Baby! Extending the new IBM Lotus Domino Blog Template
BP304 - Blog It Up, Baby! Extending the new IBM Lotus Domino Blog TemplateBP304 - Blog It Up, Baby! Extending the new IBM Lotus Domino Blog Template
BP304 - Blog It Up, Baby! Extending the new IBM Lotus Domino Blog Template
 
.NET 1.1 Base Page Framework Article
.NET 1.1 Base Page Framework Article.NET 1.1 Base Page Framework Article
.NET 1.1 Base Page Framework Article
 
ASP.NET Lecture 3
ASP.NET Lecture 3ASP.NET Lecture 3
ASP.NET Lecture 3
 

Recently uploaded

June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
Levi Shapiro
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Jisc
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
heathfieldcps1
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
BhavyaRajput3
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
Anna Sz.
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
EduSkills OECD
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
TechSoup
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
MIRIAMSALINAS13
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
Vivekanand Anglo Vedic Academy
 
678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf
CarlosHernanMontoyab2
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
Vikramjit Singh
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
Jisc
 
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Po-Chuan Chen
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
TechSoup
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
kaushalkr1407
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 

Recently uploaded (20)

June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
 
678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 

Master page in Asp.net

  • 1.
  • 2. Master Page Master page allows you to create a consistent look and behaviour for all the pages in your web applications . Master Page Design is common for all the pages. Master page actually consists of two pieces, the master page itself and one or more content pages.. A master page is an ASP.NET file with the extension .master. ContentPlaceholder control, which defines a region on the master page, is where the content pages can plug in page specific content.  A Master Page enables user to share the same content among multiple content pages in a website. ASP.NET master pages allow user to create a consistent layout for the pages in a application. When users request the content pages, they merge with the master page to produce output that combines the layout of the master page with the content from the content page.
  • 3. Master Page  Master pages in ASP.NET Web Forms start with the @Masterdirective .  The directive looks like the following. <%@MasterLanguage="C#“CodeFile="MasterPage.master.cs" Inherits="MasterPage" %>  @Page directive that is used for ordinary .aspx pages.  The directive looks like the following. <%@PageLanguage="C#” MasterPageFile="~/MasterPages/Master1.master"Title="Content Page"%>  To enable pages to insert content, the master page contains a placeholder tag <asp:ContentPlaceHolder> for individual content.
  • 4. Working with Master Page 1. To use master pages, first create a master page and add tables and other common elements. 2. Add <ContentPlaceHolder> controls to the master page from toolbox. 3. To create the content pages, add standard Web forms, select the master page check box when creating the page and then select the master page. 4. Add content to the page.
  • 5.
  • 6. Creating a Master Page  Step 1 Create new project in Visual Studio 2010 1. Go to File-> New-> Web Site-> Visual C#->ASP.NET Website-> Entry Application Name-> OK 2. Create a new web site named MasterPageDemo. 3. Right click on website in Solution Explorer and Click on Add New Item from pop up menu.
  • 7. Creating Master Page 4. Add Master Page to the application named “ MasterPage.master” and create design. Source Code
  • 9. Creating Master Page Step 2 5. In Solution Explorer, right click on website and click on Add New Item and select web form from pop-up window. 6. Change the name of the web form and select the check box of Select Master Page then click on Add button.
  • 10. Creating Master Page 7. Select the Masterpage.master and click on OK.
  • 11. Creating Master Page 8. In content Page Index.aspx, user can use the content place holder to add content to the page. Add Content Here
  • 12. Dynamically Loading Master Page  Websites uses different master pages dynamically with a content page depending upon the request.  This features enables the users to customize the appearance of the website by loading different master pages. A menu of master pages allow our users to pick their favourite layout. Steps to create dynamically loading master page as following: 1. Create two Master Page MasterPage2.master and MasterPage3.master with one ContentPlaceHolder in each.
  • 15. 2. Create a content page “DefaultPage4.aspx” using MasterPage2.page as default master page.
  • 16. 3. User can switch between master pages using links on the web page.
  • 17. Advantages of Master Page  They allow user to centralize the common functionality of user pages so that user can make updates in just one place.  They make it easy to create one set of controls and code and apply the results to a set of pages. For example, user can use controls on the master page to create a menu that applies to all pages.  They give user fine-grained control over the lausert of the final page by allowing user to control how the placeholder controls are rendered.  They provide an object model that allows user to customize the master page from individual content pages.