VB.net Tutorials with Examples

VB.Net Projects

VB.Net Project 1

adplus-dvertising
Master Page
Previous Home Next
Microsoft  ASP.NET 2.0 introduces a new feature .Master Pages. that permits you to define common user interface (UI) elements and common structure in a template that can be applied to multiple content pages in a Web application. Standard elements are, for example, navigational menus, logos, and other stock graphical elements. This allows you to have a common appearance and functionality across your Web site, avoids duplication of code, and makes the site easier to maintain. If the content pages are based on the master page, all the elements defined in the master page would automatically be defined in the content pages.

The page layout for Master Pages is easy to create, simple to maintain, and simple to assign to a Web application. The Master page provides a single point of reference for all pages to display standardized Web content. Master pages are completely transparent to end users and permit developers to create Web sites where pages share a common layout. Defining a Master page is similar to defining a normal page, but saving a Master page is    different from saving a normal page. You must save the Master pages by using the .master file extension.

How to Add Master Page in Your Application

Adding a master page to your web application is straight forward. Just right click on the project and select "Add New Item" and than select "Master Page". This will add the master page to your project. The master page already has the content place holder control which is used to hold and display your contents. Let's delete that content placeholder and add it by our self. In this case we will create two content place holders. One will be on the left and other one on the right .After you insert the content placeholder control inside your table your master page will look something like this:
 

Using the master page in your aspx pages

Just add a new aspx page and name it as "first .aspx". Now you want to use the Sample1.master file in your aspx page. Just go to the html view of your page and add a Master Page File attribute in the page directive and delete all the other html that is written in the aspx page. The Master Page File attribute denotes that the Page is inheriting from the master page.

<%@ Page  Master Page File="~/Sample1.master"  %>

Previous Home Next