tags:

views:

48

answers:

1

i have an asp.net site built using visual studio 2010 in c#. the site is basically two sections...(http://www.wsgelectronics.com for reference) the default page is the site.master page with default.aspx. I want to split into two more master pages, one for each section, car audio and computer sections if you look at the site, each with its own layout, nav bar, content etc. how would i go about linking them to work? can i have three *.master pages on one project? i didnt choose nested cause they would be completely different layouts, but i cannot find any tutorials on linking different master pages on one site. can this even be done?

+1  A: 

Yes, you can have as many master pages as you need in a given web site. When you create a Web Form (a regular .aspx page) in your site, there's a checkbox for "Select master page", so make sure that's checked. Then, when you pick your desired master page, Studio will stub out the needed markup for your page to use that master page.

For example, here's a stub of a web form that has a master in the same directory, called MasterPage.master. The relevant parts are:

  1. In the Page directive, the property MasterPageFile shows the application relative path to the master page.
  2. Master pages can have many server controls of type ContentPlaceHolder. This allows you to control where the markup in your pages are displayed. The master page I used in this example has two, one is called head and the other is called ContentPlaceHolder1. Again, those controls are defined in my master page.

Sample markup:

<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="Default" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
</asp:Content>

For more info, see Master Page Tutorials on asp.net.

wsanville
well i created the Site.master page and its default.aspx page all working fine, then in visual studio i created two more master pages with different names, in that project by clicking the project/ add new/ master page/ etc and linking them to the correct links, however, when i click the link which should take me to the correct master page i get a parser error
W S G Electronics
that it cannot find the page
W S G Electronics
im sure it has something to do with the page name, the namespace, codebehind
W S G Electronics
You can't actually request a master page in a web browser - it does not get served as a regular page. You will need to create a page (Web Form) that uses that master, and then link to that page.
wsanville
the intial master page is Site.master, th second is WSGTS.master and the third is WSGSC.master and all the codebehind looks correct for those pages, but it doesnt work
W S G Electronics
ok i understand now...i think...i just build the second and third masterpages, and continue with all the content pages, but i have those pull from its particuar master page...not the site.master, that correct...so i dont link to that master page i link to that content page...which is then linked to the correct master page...
W S G Electronics