In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article introduces the knowledge of "how to use HTML to manipulate master page content elements in web forms". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Standardizing the format of the site layout is only part of the process, and you also need to make sure that common elements, such as the site title and navigation controls, appear in the same place on each page. The key to solving this problem is to create a simple and flexible layout that can be repeatedly applied to the entire site. There are three basic ways to choose:
User control. User controls are an excellent way to standardize common page elements, but they do not solve the problem of page layout by themselves, because there is no guarantee that user controls will be placed in the same place on all pages. HTML framework. A frame is a basic HTML tool that displays multiple pages at the same time in a browser window. Its main disadvantage is that each page in it must be retrieved by a separate request server, and the code of these pages has to be completely independent. This also means that pages in one frame cannot interact with or affect pages in other frames. (at least not through server-side code) master page. Master pages are a feature of ASP.NET that is specifically designed to standardize the layout of Web pages. It defines fixed content and declares parts of the Web page that can be inserted into custom content. If you use the same master page throughout the site, you can ensure that you get the same layout. Best of all, if you change the definition of the master page, all pages that apply it will change automatically.
To provide an actionable and flexible solution for a page template, the following conditions must be met.
Be able to define a part of the page individually and reuse it in multiple pages. To be able to create a closed layout that defines an editable area. Pages that reuse this template can only add or modify content within the permitted area. The page can make some customizations to the reused elements. You can declaratively bind a page reverse template (without using code) or be able to bind to a page dynamically at run time. You can use a tool such as VS to design a page that uses a page template.
To achieve all this, ASP.NET defines two new page types: master pages and content pages.
Like a normal Web page, a master page can contain any combination of HTML, Web controls, and even code. Master pages can also contain content placeholders (defined modifiable areas).
The content page references a master page and gets its layout and content. In addition, content pages can add page-specific content to any placeholder. In other words, the content page fills the master page with missing content that is not defined by the master page.
The difference between a master page and a normal Web form is:
Master pages start with the Master directive and provide the same information as the Page directive. All Web forms start with the Page instruction. Only master pages can use the ContentPlaceHolder control, which is the part of the content page that can insert content.
After you create a master page, you get a blank page that contains only two ContentPlaceHolder controls. The first is defined in the area, which allows content pages to add page metadata, such as search keywords and stylesheet links. The second and more important ContentPlaceHolder is defined in the area, which represents what the page displays.
In addition, master pages cannot be requested directly, and to use master pages, you must create an associated content page.
Here is a simple example of a master page with a static banner, followed by a ContentPlaceHolder control, followed by a footer:
My Site
Copyright? 2008.
To use master pages in other pages, you must add the MasterPageFile feature to the Page directive:
Setting the MasterPageFile feature alone is not enough to turn a normal page into a content page. The content page must define the content to insert one or more ContentPlaceHolder controls (and write the code required for those controls). Because the master page already provides a shell, an error occurs when you try to add elements such as, and so on to the content page.
To provide content for ContentPlaceHolder, you use another special control called Content. ContentPlaceHolder and Content controls have an one-to-one relationship. For each ContentPlaceHolder in the master page, the content page provides a corresponding Content control (unless you are not prepared to provide any content for that area). ASP.NET maps them together by matching the ID of the ContentPlaceHolder and the Content.ContentPlaceHolderID property of the corresponding Content control.
Far out in the uncharted
Backwaters of the unfashionable end of the western spiral arm of the Galaxy lies
A small unregarded yellow sun.
Custom Title
To better understand how master pages work, it's worth looking at the content pages by tracking (adding Trace=true to the Page directive). In this way, you can understand the hierarchy of the control. You will find that ASP.NET first creates control objects for master pages, including ContentPlaceHolder (which acts as a container), and then adds controls to the content page to ContentPlaceHolder.
If you need to configure the master page or content page dynamically, you can respond to the Page.Load event in either class. Sometimes you may use initialization code in both master and content pages. In this case, it is important to understand the order in which each event occurs. ASP.NET first creates a master page control, and then adds child controls for the content page. It then triggers the Page.Init event for the master page, followed by the Page.Init event for the content page. The same steps are used for the Page.Load event. (if there is a conflict, the customization of the content page will overwrite the changes made at the same stage of the master page)
Master pages can include default content when defining ContentPlaceHolder (content that will only be used if the content page does not provide the corresponding Content control).
Content pages cannot use only part of the default content of the master page or edit only this part. This is not possible because the default content is saved in the master page rather than in the content page. All, either use it completely or replace it all.
HTML uses a flow-based layout. This means that as the content increases, the page will be reorganized and some other content will be pushed aside. This layout makes it difficult to obtain the expected results of the master page. If you are not careful, it will destroy the perfect layout, and the large amount of information inserted into the tag will mess up the page structure.
To control these problems, most master pages use HTML tables or CSS positioning to control the layout.
When using tables, the basic principle is to break down the entire page or part of the page into rows and columns. You can then add ContentPlaceHolder to a cell to ensure that the rest of the content is more or less aligned as expected.
When using CSS positioning, the basic idea is to put the content into the tag, then use absolute coordinates to control the location or let them float on one side of the page, and finally you can put the ContentPlaceHolder into the tag.
This is the end of the content of "how HTML calls to manipulate master page content elements in web forms". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.