Introduction to basic knowledge of ASP. NET master pages and basic knowledge of asp.net
What is a template page?
Using the template page, you can easily and quickly create a unified style ASP. NET Website, and it is easy to manage and maintain, improving efficiency.
The template page defines the appearance and standards required by the web page. Each content page containing the displayed content is created on the basis of the master page. When a user requests a content page, these content pages are merged with the master page. In this way, the layout of the template page and the layout of the content page can be combined and output.
The template page is generally used:
1. Modify the template page to process general functions of the webpage.
2. You can easily create a group of controls and codes and apply them to a group of web pages.
3. By allowing the display of placeholder controls, the template page can control the layout of the final page in details.
Template page and general page
Create a template page in vs to see what is different from the general content:
@ Master replaces @ Page with multiple replaceable placeholders ContentPlaceHolder.
Associate a common page with a master page:
MasterPageFile, the attribute of a common page, will prompt you to select the master page to use, or select to use the master page when creating the page, you can also apply a master page to a common page.
DEMO:
Template page code:
<% @ Master Language = "C #" AutoEventWireup = "true" CodeFile = "MasterPage2.master. cs" Inherits = "template page _ MasterPage2" %> <! DOCTYPE htmlPUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN "" http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd "> <Html xmlns =" http://www.w3.org/1999/xhtml "> <Head id =" head1 "runat =" server "> <title> template page </title> <asp: ContentPlaceHolderidasp: contentPlaceHolderid = "head" runat = "server"> </asp: ContentPlaceHolder>
Content Page code:
<% @ Page Title = "" Language = "C #" MasterPageFile = "~ /Template page/MasterPage2.master "AutoEventWireup =" true "CodeFile =" ContentPage. aspx. cs "Inherits =" ContentPage "%> <asp: ContentIDasp: ContentID =" Content1 "ContentPlaceHolderID =" head "Runat =" Server "> </asp: Content> <asp: contentIDasp: ContentID = "Content2" ContentPlaceHolderID = "ContentPlaceHolder1" Runat = "Server"> <p> add Content page </p> </asp: Content>
Display:
Master pages and themes:
It is the same as the master and topic in the PPT. Yes:
You can add your own content based on the template, which is equivalent to a good framework and style. The master is equivalent to a component. You need to build the framework and style on your own. The master node abstracts the same unchanged parts from multiple similar structured webpages and can be applied to more webpages to save time.
Does this simple example help you better understand how to use the master page? I hope you will continue to pay attention to the articles shared by xiaobian.