Ocean studio-website construction expert: ASP. NET: how to convert your site to a masterpage site in 3 steps

Source: Internet
Author: User
ArticleDirectory
    • 1. Create a New masterpage
    • 2. Link your old pages to your masterpage in the page Directive
    • 3. Tell the masterpage what content goes where
Once you have your design converted into HTML/CSS, why shocould you have to worry about breaking it every time you create a new page? Abstract yourself from this with masterpages, while still enabling yourself to easily make design changes. masterpages are wonderful for standardizing your site and your design, in addition to making it easier to maintain and to build new pages. they are a very powerful and easily customizable way to template your site. this article is for those who don't have much or any experience with masterpag Es or are converting an old ASP. Net site to a masterpage-driven site. If this is you, don't be afraid-you can do it in just three easy steps!

1. Create a New masterpage

Right click your project, go to "add" and then "new item ..." And select masterpage. Name it something useful, like "Main. Master" and hit OK. You shocould be presented with a barebones XHTML skeleton. notice that your skeleton has this tag in it:<Asp: contentplaceholder id = "contentplaceholder1" runat = "server"/>. This is the location where your content will be loaded from your. aspx pages. fill your new masterpage with the XHTML that you wish to use on every page. if you want some things to change based on certain variables, you can do so in the codebehind. treat the masterpage like any other. ASPX page. the only thing different about it (on a basic level) is that it does not contain your content, but rather what encompasses your content.

2. Link your old pages to your masterpage in the page Directive

In your <% @ page directive, add the following attribute:Masterpagefile = "~ /Yourmasterpage. Master"

3. Tell the masterpage what content goes where

If you only have one contentplaceholder, you will add the following tag around all of your content in your. aspx pages:<Asp: Content ID = "content1" contentplaceholderid = "contentplaceholder1" runat = "server">Hello, world!</ASP: content>, Where "contentplaceholder1" is the ID of the placeholder in your masterpage that you linked to in step 2. if you have more than one contentplaceholder in your masterpage, simply wrap the tags around the correlating content.

And that's it! That's really all there is to it! Just apply steps 2 and 3 to each of your. aspx pages. There is an optional step for those who may have changed their pages 'codebehind inheritance:

4. Change codefile inheritance

Simply replace whatever inheritance you haveInherits system. Web. UI. Page

Please read my articles ASP. net: How to easily reference masterpage members and my asp. net and Ajax: so freaking easy series for more tips on how to get yourself set up even better using masterpages.

 

Address: http://dotnetdiscussion.net/2008/01/11/aspnet-how-to-convert-your-site-to-a-masterpage-site-in-3-steps/

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.