WorldofASP.NET : ASP.NET Directory, Tutorial, Hosting, and Source Code
You are 1 of 57 users


WorldofASP.NET >> ASP.NET >> Unedited ASP.NET

How to use masterpage in ASP.net

This article will explain about masterpage with example
Published Date : 30 Jun 2009
Author : wilsinky
Language : C#
Platform : .NET
Technology : ASP.NET
Views : 2638
Rating : (0 votes so far)



Master Page


A Master Page enables you to store the same content among multiple content pages in a website. You can use Master Page to create a common page layout. Master Pages allow you to create definitive styles for your web pages, and they have a higher precedence than CSS Stylesheets.

For example, if you want all the pages in your website to share a three-column layout, you can create once in a Master Page and apply the layout to multiple content pages.

You also can use Master Pages to display common content in multiple pages. If you want to display a standard header and footer in each page in your website, then you can create the standard header and footer in a Master Page.

Note the @ Master instead of the usual @ Page declaration.
<%@ Master Language="C#" AutoEventWireup="true"
CodeFile="MasterPage.master.cs" Inherits="MasterPage" %>

Note the @Page declaration on web.aspx is:
<%@ Page Language="C#" AutoEventWireup="true"
CodeFile="Default.aspx.cs" Inherits="_Default" %>

On this page declaration, we don’t have a MasterPageFile.
We can add masterpagefile into web.aspx page, so we can using template into many page .aspx.
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="web.aspx.cs"
Inherits="web" MasterPageFile="~/MasterPage.master" %>

After we declare page declaration, we must delete content like HTML,HEAD,BODY, FORM, etc. We don’t need that tag because we have used MasterPage.Master.

Now, we try to make a MasterPage.Master. Right click on Explorer – Add New Item – Choose MasterPage and Visual C#. After we add that, we design MasterPage.master as we like. We can divide the web page into 3 rows, such as: header, content, and footer.

We can add image, logo, or Text about our web into Header Page. On the footer page we declare information about year production of website, etc.

We can declare Content PlaceHolder Control from toolbox into content page. On this part, we can modify the page to your liking (color, table, font, etc).

Let's we begin to make a simple website using mastepage. Put this code into MasterPage.Master.


After we make MasterPage.Master, we create two pages (login, and registration page).

Login Page


Registration Page


The output of our code is:




Explain: we declare header and footer in master page because of that we can use the same template in any page. Like on login.aspx and registration.aspx page. They have the same template, but the different content.

References

Include all the useful links or references that can help users learn about your tutorial

  1. Search Engine
  2. ASP.NET Resources
  3. code project

Download Source Code




Other Related and Popular Articles :

Simple asp2 feedback form
A simple way to get user feedback via webpage email.

Basics of XHTML-MP
Basics of XHTML-MP

181
181

Custom Validation for DOB Using three dropdownlist
This article is exactly usefull to validate date of Birth having three dropdownlist control.

Repeater within Repeater
this article is used to show hierarchical data using repeater control.

Introduction to Data Binding in ASP.NET 2.0
This article explains the basic concept about Data Binding in ASP.NET 2.0


Author Profile : wilsinky

Click here to view Author Profile


How would you rate the quality of this content?
Poor Excellent

Comments

Leave New Comments


Article Content copyright by wilsinky
Everything else Copyright © by WorldofASP.NET 2010

Category
.NET 3.5
AJAX and ATLAS
ASP.NET
C# Programming
Classic ASP
Enterprise Systems
General .NET
VB.NET Programming
Announcements
Earn Cash by writing an article or review
For more info Click here







Legend : - Within 3 Days - Within 6 Days - Within 9 Days

Home | Add Resources | Sponsored Listings | Advertise with Us | SiteMap 1 | SiteMap 2 | Link To Us | Contact Us
© 2002-2010 Worldofasp.net ASP.NET Directory, Hosting and Tutorials | All rights reserved
Our Partners : ASP.NET Web Hosting | ASP Hosting | ASP.NET Hosting | Phone Card | Calling Card |Stock Investing