ASP. NET 2.0 data Tutorial: Create a master page

Source: Internet
Author: User

Generally, user-friendly and personalized websites have consistent page layout and navigation systems. The two new features introduced by asp.net 2.0 provide us with simple and effective tools for unified site page layout and site navigation. They are master pages and site navigation. The master page allows developers to create uniform site templates and specified editable regions. In this way, the aspx page only needs to provide the filled content for the Editable area specified in the template page, all other tags defined on the master page will appear on all aspx pages that use the master page. This mode allows developers to manage and define the page layout of the site in a unified manner, so that they can easily obtain pages with a unified visual and Visual View and easy to update.

The site navigation system allows developers to define site maps and provides APIs to query site map information through programs. The new navigation controls include Menu, TreeView, and SiteMapPath, which can easily display all or some site maps in a general navigation user interface element. We will use the default site navigation provider, which means that our site map will be defined in an xml format file.

To illustrate these concepts and make the sample site of our tutorial more available, let's use this course to define a unified page layout for the site, implement a site map, and add a navigation UI. At the end of this course, our course sample site will have a beautiful design effect.

 

Figure 1: final results of this course

Step 1: Create a master page

The first step is to create a master page for our site. ).

I organized these pages and files to illustrate that the data access layer and business logic layer described in the previous two courses will reuse these examples in more details of future courses.

 

Figure 2: files in our project

To create a master page, right-click the project name in solution manager and select Add new project. Select the master type from the template List window and name it Site. master.

 

Figure 3: Add a master page to the site

Define the unified page layout of the site on the master page. You can use the design view to define the layout or controls you need. You can also manually add tags to the Code view. On our homepage, use the Cascading Style Sheet defined in the external document style.css to define the position and style. You may not know how to display the following labels. The style sheet rules define that the content of the <div> label used in the navigation is absolutely positioned on the left side of the page and the width is fixed to 200 pixels.

 
 
  1. < %@ Master Language="C#" AutoEventWireup="true" CodeFile="Site.master.cs" Inherits="Site" 
  2.  %>  
  3.    
  4.  < !DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
  5.    
  6.  < html xmlns="http://www.w3.org/1999/xhtml" >  
  7.  < head runat="server">  
  8.      < title>Working with Data Tutorials< /title>  
  9.      < link href="Styles.css" rel="stylesheet" type="text/css" />  
  10.  < /head>  
  11. < body>  
  12.     < div id="wrapper">  
  13.  
  14.         < form id="form1" runat="server">  
  15.  
  16.             < div id="header">  
  17.                 < span class="title">Working with Data Tutorials< /span>  
  18.                 < span class="breadcrumb">  
  19.                  TODO: Breadcrumb will go here< /span>  
  20.             < /div>  
  21.  
  22.             < div id="content">  
  23.                 < asp:contentplaceholder id="MainContent" 
  24.                  runat="server">  
  25.                   < !-- Page-specific content will go here -->  
  26.                 < /asp:contentplaceholder>  
  27.             < /div>  
  28.  
  29.             < div id="navigation">  
  30.                 TODO: Menu will go here  
  31.             < /div>  
  32.         < /form>  
  33.     < /div>  
  34. < /body>  
  35. < /html>  
  36.  

A master page defines a fixed layout and editable areas that can be filled with the aspx pages that use the master page.

The editable area is displayed through the ContentPlaceHolder control and is located in the <div> flag. The master page only has one ContentPlaceHolder (MainContent), but the master page can contain multiple ContentPlaceHolder controls.

Enter the above tag and switch to the design view to observe the layout of the master page. All the aspx pages that use this master page have such a uniform layout, and the MainContent area is reserved for the aspx page to show its talents.

 

Figure 4: master page displayed in design view

  1. ASP. net mvc Path Selection System Construction
  2. URL path selection scenario in ASP. net mvc Framework
  3. URL path selection rules of ASP. net mvc Framework
  4. ASP. net mvc Framework: Use a strong type class to pass ViewData
  5. Use ASP. net mvc framework to create an e-commerce website

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.