ASP.net 2.0 Create content page

Source: Internet
Author: User
Tags bind new features window visual studio
Asp.net| creation After creating a full master page, it is necessary to create a content page. From a user's point of view, the content page has the same access path as the final result page, which seems to indicate that the two are the same file, not actually. The resulting page is a virtual page with no actual code, and its code content is the result of merging master pages and content pages at run time. Before you begin to introduce content pages, there are two other concepts that need to be emphasized: first, that all content in a content page must be included in the contents control, and that the content page must bind to the master page. Although the extension of a content page is the same as a regular ASP.net page, its code structure is very different. In creating a content page, you must always keep in mind the above two important concepts.

As with creating a master page, the process of creating a content page is relatively straightforward. You can open the window shown in Figure 1 by clicking Add New Item ... on the Web Site command menu, or by right-clicking the project in Solution Manager and choosing Add New Item ... in the Drop-down menu.

As shown in Figure 1, you are asked to select a new file type. Because the content page is the same as the extension of the normal. aspx page, the Web Forms icon is selected. Next, you need to set the filename index.aspx. After the settings are complete, you cannot click the Add button directly. Because a content page must bind to a master page, you also need to set the check box "put code in separate files" and "Select Master Page". The former has been described in the previous article, highlighting the latter. The Select master Page check box is used to set whether the Web form you are creating binds to the master page. If you are creating a content page, you must select this option. After you've finished, you can click the OK button to eject the window shown in Figure 1.

The left side of the window is the project folder, and the right side is the list of master pages in the folder. Figure 1 shows a window in which you have just created the master page masterpage.master, select the file, and click OK. With the above steps, you can successfully create a content page that binds the master page masterpage.master index.aspx.



Figure 1 Adding a content page



Figure 2 Selecting a master page

The following lists the source code for the content page index.aspx:


Content page index.aspx File source code

<%@ Page language= "C #" masterpagefile= "~/masterpage.master" autoeventwireup= "true" codefile= "Index.aspx.cs" inherits= "Index" title= " sample 5-1"%>

<asp:content id= "Content1" contentplaceholderid= "ContentPlaceHolder1" runat= "Server" >



</asp:Content>

<asp:content id= "Content2" contentplaceholderid= "ContentPlaceHolder2" runat= "Server" >

<p> </p><p> </p>


<p> This page is developed using the new features of the master page from ASP.net 2.0 technology. Includes two main pages: Master pages and content pages. The master page suffix name is. master, which encapsulates the shared elements in the Web site. The content page is actually an ordinary. aspx file that contains additional content in addition to the master page. At run time, ASP. NET engine merges the two page contents and finally sends the results to the client browser. </p>

</asp:Content>

The bold code above is the code structure for the content page. As you can see, the content page differs from the normal. aspx file in the code. Content pages do not have key web elements such as
The design-time screenshot of the content page index.aspx is shown in Figure 3.



Figure 3 Content Page design-time view

On the same page, Visual Studio 2005 supports visual editing of content pages, and this support is based on read-only display master page content. In edit state, you can view the appearance of the page after the master and content pages are grouped, but the master page content is read-only (rendered gray), not editable, and the content page can be edited. If you need to modify the master page content, you must open the master page.

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.