C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




Master Page in ASP.NET 2.0


Posted Date: 21 Aug 2006    Resource Type: Articles    Category: Web Applications
Author: Vikram Singh KshatriyaMember Level: Gold    
Rating: Points: 10



Introduction



On many web sites, it is important to achieve a consistent "look and feel" as the user moves from page to page.While this was possible with .NET 1.1 but it was difficult and required much effort and discipline both by programmer and designer. ASP.NET 2.0 makes this far easier with the creation of master pages.
A master page provides shared HTML, controls, and code that can be used as a template for all of the pages of a site.

What are Master Pages ?


Master pages let you make a consistent layout for your application, you can make one master page that holds the layout/look & feel and common functionality of your whole application and upon this master page, you can build all the other pages, we call these pages Content Pages. So simply you can build your master page and then build content pages, and while creating the content pages you bind them to the master page you have created before, those two pages are merged at runtime to give you the rendered page.

Designing the Master Page


A master page is defined using the following code:

%@ master language="C#" %

You can also add a master page in Visual Studio 2005 using "Add New Item" menu of the project and selecting "Master Page" template.The master page is saved as .master extension.

A master page also has a ContentPlaceHolder control (asp:contentplaceholder). This control actually hosts a page which is inherited from the master page. For example, if we inherit a page "Login.aspx" from master page, the contents of "Login.aspx" will be displayed in the ContentPlaceHolder control of master page.


Designing the Sub Pages


The pages you'll add that will use this master page will put all of their content into the ContentPlaceHolder you've added to the Master.

Note: You can put more than one ContentPlaceHolder object on a master page (each has its own ID), so this does not limit your flexibility.

Using Sub-Master Pages


It is not unusual for you to want to have certain elements that are stable throughout the entire application, but other elements that are shared only within one part of your application. For example, you might have a company-wide header, but then have division-wide elements, as well. ASP.NET 2.0 lets you create sub-master pages. Any given .aspx page (web form) can be combined with a sub-master or with the original master, whichever makes more sense for that individual page.

Summary



Since the release of ASP.NET 1.0, ASP.NET has earned a reputation of writing Web applications faster and now with the help of new and enhanced features of ASP.NET 2.0, Web developers will find themselves writing 50% less code than ASP.NET 1.0. In this article, you saw how master pages can be used to define various common layout pages of a site and reuse them in your sub pages. In my forthcoming articles, I will explore other new features of ASP.NET 2.0.









Paragraph Heading N





Summary







Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
(No tags found.)

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Provider Model in ASP.NET 2.0
Previous Resource: .NET Remoting
Return to Discussion Resource Index
Post New Resource
Category: Web Applications


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design


Contact Us    Privacy Policy    Terms Of Use