cool hit counter ASP. Net uses form master pages wisely_Intefrankly

ASP. Net uses form master pages wisely


Copyright: This is an original post by the blogger and may not be reproduced without the blogger's permission. https://blog.csdn.net/huyuyang6688/article/details/38865931

Background: The basic framework structure of each web page is similar to.

When browsing websites, you will find that in many websites, the basic framework of each page is the same, for example, at the top is the title of the website, in the middle is the content, and at the bottom is the copyright of the website, the development provider, and other information.

In these pages, the style and content of the header and bottom of the table are the same, all that differs is the content in the middle.

So when creating a website, you can separate out these common things and put them in a "form master page" and nest them when needed.

Crafting form mastering items.

Here goes (this article is using VisualStudio 2013 as the programming environment and may differ from other versions in some steps, so please note for yourself).

1. Add a Web form master page test.Master in the project: right-click the project - Add - New Item - Web form master page.

<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="test.master.cs" Inherits="Web.test1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>
    <asp:ContentPlaceHolder ID="head" runat="server">
    </asp:ContentPlaceHolder>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:ContentPlaceHolder ID="contentPlaceHolder" runat="server">
        
        </asp:ContentPlaceHolder>
    </div>
    </form>
</body>
</html>

2、In the form master pagetest.Master of<head> Add between tagsCSS、JS et cetera( Here first just add theCSS documents as an example):

<head runat="server">
    <link href="css/common.css" rel="stylesheet" />    <%-- Add QuoteCSS documents--%>      
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title></title>
    <asp:ContentPlaceHolder ID="head" runat="server">
    </asp:ContentPlaceHolder>
</head>

3. Edit the form master page test. Master, add the public content of each page (here the layout of the page is the layout above as an example, the css style of the three divs will not be illustrated for now).

<body>
    <form id="form1" runat="server">
        <div id="top">                                 <%-- Public styles for each page: Page header--%>
            <h1> So-and-so website</h1>
        </div>
            
        <div id="main">                                <%-- Different styles for each page: Page body content--%>
            <asp:contentplaceholder id="contentPlaceHolder" runat="server">
                 <%-- Here for each nested this master different contents of the various pages of the--%>
            </asp:contentplaceholder>
        </div>     

        <div id="footer">                              <%-- Public styles for each page: Web Copyright Information Area--%>
            <p> all rights reserved (copyright statement):******</p>
        </div>
    </form>
</body>

4, nesting form master pages in each web page test. Master: right-click the project - Add - New Item - Web form containing the master page test.aspx, select test.Master in the Select Master Page dialog box, OK, the generated page is

<%@ Page Title="" Language="C#" MasterPageFile="~/common.Master" AutoEventWireup="true" CodeBehind="test2.aspx.cs" Inherits="Web.test2" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="contentPlaceHolder" runat="server">
</asp:Content>

At this point this form test.aspx and the master page test.Master are running the same, the next step is to add the different content from each page.

5、 this time, web pagetest.aspx inContentPlaceHolderID=“head” harmonyContentPlaceHolderID=“contentPlaceHolder” of<asp:Content> It's the equivalent of a master pagetest.Master corresponding to<asp:Content>。 So if every page would have the same part, Then you can write the same part in the corresponding place on the master page, And writing the different content of each page in theContentPlaceHolderID=“contentPlaceHolder” of<asp:Content> in。

for example, (prefix indicating ordinal number, e.g. first, number two etc)4 step in, this onetest.aspx This style is already nested, Its subject matter reads “ Website content Website content Website content Website content……”, followtest.aspx The code in:

<%@ Page Title="" Language="C#" MasterPageFile="~/common.Master" AutoEventWireup="true" CodeBehind="test2.aspx.cs" Inherits="Web.test2" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="contentPlaceHolder" runat="server">
    <p> Website content  Website content  Website content  Website content…… </p>
</asp:Content>

If I build another page called test1.aspx, which is the same except that the main content is different from that in test1.aspx, then I can have test1.aspx nest the master page test.Master, with the following code.

<%@ Page Title="" Language="C#" MasterPageFile="~/common.Master" AutoEventWireup="true" CodeBehind="test2.aspx.cs" Inherits="Web.test2" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="contentPlaceHolder" runat="server">
    <p> Website content1  Website content1  Website content1  Website content1…… </p>
</asp:Content>

Expand: Master Page Nested Master Pages

When all pages within the entire site are not of this style, Rather, a large website is divided into several sections, Uniform styling of pages in each section, This is the time to nest a master page with a master page:

Now create another master page (I've named it "child master page" here) and use it to nest the above master page test. Master, code for.

<%@ Master Language="C#" MasterPageFile="~/test.Master" AutoEventWireup="true" CodeBehind="m_common.master.cs" Inherits="Web.admin.m_common" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="contentPlaceHolder" runat="server">    
    <asp:ContentPlaceHolder ID="contentPlaceHolder_child" runat="server">
         <%-- This is nested“ (computing) sub-page” different contents of the various pages of the--%>
    </asp:ContentPlaceHolder>
</asp:Content>

Note that the first line of the code has MasterPageFile="~/test. Master" is the address of the master page to be nested, and "~" is the current directory.

Benefits of nested page master items.

It is possible to useVisualStudio in the form master page to wrap the same parts of each page, When creating pages with the same structure, Then you can directly nest this form master page, Avoids duplication of code, Improved code reusability; additionally, If you want to change the style of a section or even an entire website, then simply modify the master page and the master page introduced in the<script> etc. documents, Improved maintainability of code, Adequate representation ofOOP ideas。


Recommended>>
1、How do leaders perceive blockchain This book published by Peoples Daily Press gives the answer
2、Shenzhen Application for the 2018 Entrepreneurship Subsidy for Studying Abroad Students begins
3、Tencent Foraging officially opens to the public using AI for medical image analysis and assisted diagnosis and treatment
4、Can blockchain save ofo as body ads are banned
5、These 5 superb prototyping tools are even easier to use than AXURE and SKETCH

    已推荐到看一看 和朋友分享想法
    最多200字,当前共 发送

    已发送

    朋友将在看一看看到

    确定
    分享你的想法...
    取消

    分享想法到看一看

    确定
    最多200字,当前共

    发送中

    网络异常,请稍后重试

    微信扫一扫
    关注该公众号