Asp.net| in order to reduce the page in the design of the change in the page to move the whole station, vs2003 upgrade to the VS2005 after adding the concept of the master.
You can think of it as a "Web Template", and the difference is, no longer need to update every page, modify once, all the pages will change, do it once and for all.
Let's start with a simple master demo:
1. First open Visual Studio 2005, create a new asp.net Web site, file system, C #.
2. In Solution Explorer, right-click to create a new key:
3, select the master page:
4, open Masterpage.master, there is a ContentPlaceHolder control, pay attention to what the control inside write something.
Let's go to Design view and add header and footer to the control.
5, after saving we can use it to do other pages. There are two ways to do this, 1 is to right-click anywhere on the master page, click Add Content page, 2 create new item on Solution Explorer, and tick select master page when you generate ASPX page
6, select the appropriate master page
7, in the newly generated page source code only these words:
- <% @PageLanguage = "C #" masterpagefile= "~/masterpage.master" autoeventwireup= "true"
Codefile= "Default2.aspx.cs" inherits= "Default2" title= "Untitledpage"%>
-
We can see a content control that corresponds to the ContentPlaceHolder1 control of the master page and translates to the view page:
8, the page header and footer text are gray, we can only edit in the content.
After saving to visit default2.aspx this page, F5., we see the page:
9, and imagine the same, let's take a look at the source code:
- ! Doctypehtmlpublic "-//w3c//dtdxhtml1.0transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
-
- </li> <li>Untitledpage</li> <li>
-
-
- Value= "/wepdwulltewmduynjyzmjhkzashjahe9xmxuhpboeonmx2y6xyi"/>
-
- Thisisthepage ' Sheader
- Thispage ' scontent:hello,world!
- Thisisthepage ' Sfooter
The master content is placed in a div, and the contents page is not placed in a separate div, which means that the master does not add any extra code to the child page. This gives us the programming and the page layout to bring the very great flexibility, we may make full use of the Css+div form localization, also may use the table way to carry on the localization. You don't have to modify each page to modify it.
10, for the master is not a fixed content, we can use a number of ContentPlaceHolder1 to layout, the following example is used to locate the table:
11, in the corresponding sub-page will have two content:
Generated code:
- ! Doctypehtmlpublic "-//w3c//dtdxhtml1.0transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
-
- </li> <li>Untitledpage</li> <li>
-
-
- Value= "/wepdwukmty1ndu2mta1mmrkpjwlpyqa5jxcw5ivhc0niyajqtu="/>
-
- Thisisthepage ' Sheader
- OhmyContent1
|
- HimyContent2
|
- Thisisthepage ' Sfooter
12, to flexible application, although CSS can also use div to solve this problem, but some non-standard control appearance is difficult to control with CSS, if you do another set of Master Masterpage2.master, you can dynamically set in the page:
protected void Page_PreInit (object sender, EventArgs e)
{
MasterPageFile = "~/masterpage2.master";
}
First here, it is said that can also be nested applications, but now is enough, with the use of theme, next time.