Introduction

In this tutorial we will learn how to create a master page in visual studio 2010. This tutorial gives you a quick reference to making a master page for your project in order to create web pages with a consistent layout. The code presented in this tutorial is in C#.

Creating and using master pages

Master pages are used to create a consistent layout in a website. Master pages are very similar to templates in that they can define the look and feel of your website in a single location. There can be more than one master page depending on the project and how many different themes you incorporate into it. Creating a master page is very simple.

1. In visual studio right click on the name of the website project in the solution explorer and select new folder the name the new folder Master Pages.

2. Right click on the name of the website project again and select Add New Item. When the templates menu opens, select Master Page from the list.

3. When the master page is generated click and drag it into the master pages folder you created.

4. While building your project be sure to use ContentPlaceHolder controls for the areas that will be occupied by the content pages.

5. After you have built your master page, to add a content page simply add a web form to the project and make sure the use with master page box on the bottom right of the templates menu is checked.

Conclusion

Masterpages can be used for all sorts of things, but a great way to use them is to layout a webpage. You will notice on many websites the layout over many pages is similar(header, footer, nav menus, etc.). This can be easily achieved using Master Pages to lay out the page before creating them all. Once you have created the Master page the Production time of the rest will be cut dramatically.