Community-Credit.com | NonProfitWays.com | SOAPitstop.com   Skin:   
      User: Not logged in 
Home
Newsletter Signup
XSLT Library
Latest XML Blogs
Featured Examples
Presentations
Featured Articles
Book Chapters
Training Courses
Events
NewsGroups
 
Discussions
Examples
Tutorials
Tools
Articles
Resources
Websites
 
Sign In
My Profile
My Articles
My Examples
My Favorites
My Resources
Add a Resource
Logout
 
About Me
My Blog
HeadGeek Articles
Talking Portfolio
Resume
Pictures
World Trip Pics

Master pages in Asp.net 2.0
Author: Rajendra Kumar
Published: 6/29/2006 5:47 AM
Category: ASP.NET
Summary: This Article Explains briefly about Master Pages in Asp.net 2.0

 

 

 

Introduction

 

Generally when we are developing a web Application, some web pages require consistent look like header and footer to achieve that we used user controls. And now Asp.net 2.0 has got a new feature called MASTER PAGES , one of the most anticipated feature  provide a sanctioned and elegant way of designing pages in an application based on templates.

 

Master Pages

 

 Master Pages enables the developers to create a consistent look through out the application. Master page has .master as its extension. A master page contains a new ‘Master’ directive. The implementation of Master Pages in ASP.NET 2.0 consists of two conceptual elements: Master Pages and Content Pages.

Master Pages act as the templates for Content Pages, and Content Pages provide content to populate pieces of Master Pages that require filling out.

 

The Master Page file serves as the template for other pages, so typically it will contain the top-level HTML elements, the main form, headers, footers, and such. Within the Master Page you add instances of the ContentPlaceHolder control at locations where you want Content Pages to supply page-specific content.

 

In contrast, Content Pages are just ordinary .aspx files that specify an associated Master Page in their page directive using the masterpagefile attribute. These pages must contain only instances of the Content control as their sole purpose is to supply content for the inherited Master Page template. Each Content control must map to a specific ContentPlaceHolder control defined in the referenced Master Page, the contents of which will be inserted into the Master Page's placeholder at rendering time

 

Let us see how to create a simple master page

 

<%@ Master Language=”C#” %>
<script language=c# runat=server>
// code
</script>
 <html>
<head><title>Master Pages in Aspx 2.0</title>
<body>
<form runat=server>
 <asp:ContentPlaceHolder ID=”MyContentPlaceHolder” runat=”server”>
<h2>Hi this is Example for Master pages </h2>
</asp:ContentPlaceHolder>
 </form>
</body>
</html>
In the above code there is a ContentPlaceHolder control there is some content. This content will render in any content page that doesn’t reference this ContentPlaceHolder’s ID, so in effect you can have default content on all your content pages which is overridden if you have content.

 Master page can contain numerous content areas using ContentPlaceHolder controls just make sure to match up the ContentPlaceHolder’s ID in your pages. Basically want happens is that when your .aspx page renders, it will cycle through all the Content controls and match up the PlaceHolder in the master page.

 

Configuration Options

 

We can use a Master Page to be used by default for all pages in an application by adding a pages element to your web.config file specifying a common Master Page

 

<configuration>

         <pages masterPageFile=”ExampleMaster.master” />

</configuration>

Like any settings specified at the application level, individual pages can elect to override the default masterPageFile attribute, but adding this to your configuration file will guarantee that no pages will be added to your application accidentally without an associated Master Page.

 Nesting Master pages

 To nest one master page within another page, a process called "Nesting Master Pages". Nesting support is built-in, which means you don't have to do anything special to reap the advantages of nested master pages; a content page that uses a sub-master page will automatically receive content from all the master pages in the hierarchy.

 Summary

This article explained Master Pages, the new concept in Asp.net 2.0. This would  useful for the beginners of this concept

 


 

 
Fans of "The Office"
Dwight Bobbleheads are here!
  “It's me! I'm the bobblehead! Yes!”



Advertise on XMLPitstop

Advertise on XMLPitstop


EggHead Cafe
Web Servicee development
DotNetSlackers
Buy text ads here!
remote file backup
Color Laser Printer
Fendi sunglasses
Skype vs. sipcall
VoIP Internettelefonie
Buy text ads here!

Interested in Text ads?
2,223 Total Members
36 members(last 30 days)
8 members(last 7 days)
2 members(today)

1,609 Total Discussions
12 Posts(last 30 days)
0 Posts(last 7 days)
0 Posts(today)

17,260 Total Blog Posts
1,839 Blogs(last 30 days)
342 Blogs(last 7 days)
49 Blogs(today)

8,699 Newsgroup Posts
0 Posts(last 30 days)
0 Posts(last 7 days)
0 Posts(today)

13,786 Total Resources
5 Resources(last 30 days)
1 Resources(last 7 days)
0 Resources(today)


 

David Silverlight's XMLPitstop.com| 2801 Florida Ave #225|Miami, FL 33133|Ph:305-447-1139