Home Articles My Account Messages Tools Join
Tech Blog, ASP.Net, VB.Net, C#.Net, Programming Help, Help Guide
StellarPC.com | What is a Master Page used for? (ASP.Net)
What is a Master Page used for? (ASP.Net)
Written by: Justin Rich

What is a Master Page used for?

Master Pages in ASP.Net are a new solution to an old tedious problem. Actually, Master Pages have been around since Visual Studio 2005 was released for .Net 2.0 framework. What the Master Page does for you is that is creates a template. Most websites, such as this one, have many similar componants that are resident on every page. On this site, it's the header area with the links and the footer area with the repeat logo and copyright information. Rather than having to create user controls that get included in every page or coding the HTML for the header and footer into every page, we use a Master Page.

How to create a Master Page
In your web application project, right click on the project and go to 'Add'. When you get the dialog box for new types of objects to add, choose the Master Page and give it a good name that you'll know it by. It defaults to Site1.Master. The .Master extension helps identify it among the other files in the project. Once it's created, you'll see what looks very much like a normal .Net webpage or .aspx page, but it will have 2 embedded sections for the head area and the content area. You can add HTML to anywhere on this page and format it for your header and footer area and if you've already created these in user controls, just embed them here. Once complete, you can then create pages that rely on the master.

How to create content pages
Content pages or the content form are normal .aspx pages but when you choose the option called 'Web Content Form' you will be given a prompt to base it off of an existing master page and it will list all masters in your project. Choose the appropriate one and create the page. Once this is done, you will see the same 2 embedded content ares in the HTML source side. One is for the Head and the other for Content. Place the standard Head tags inside the Head content, such as the <title> tag to override the title from the master itself. Without overriding, you'll get what's in the Master. Put the rest of your HTML in the content. This can be .Net controls or 3rd party controls at your leisure. This will all work the same as normal pages. When you view the page 'Design' you'll actually see the design of the Master page greyed out in the background and the content you're creating falling into the Master page's content area.

This solve the dilema of the redundant header/footer/sidebar controls that we were writing into every page back in the days of 1.1 or prior... no more #includes.

If you have any specific questions, please feel free to ask.
New Post Next 50 | Previous 50
Post# Subject: Posted By: Time:
New Post Next 50| Previous 50