Implement homepage nesting in ASP. NET2.0 (1)

Source: Internet
Author: User

Today, many commercial companies have different departments, and these departments have their own sub-websites on the company's website. Generally, each department maintains its own website based on its own needs. Although this will enrich the company's website, it will cause inconvenience to users, that is, because the sub-websites of various departments are not consistent, it is difficult for users to browse the website. Fortunately, ASP. NET2.0 provides us with a solution, namely homepage nesting.

Create a nested Home Page

First, you need to create a standard homepage. You need to add some shared items on this homepage, such as the company Logo, company name, footer, and menu, the standard homepage must be used for sub-websites of each department. Each department can establish its own homepage based on its own business needs, and then embed the homepage of these departments into the standard just created. In this way, both the end user and the Department are good. For the end user, no matter which department he accesses, the website will see the same Logo, menu, and footer. For departments, they can build an embedded home page based on their own business needs. This is like an OCX control embedded on a webpage.

To understand how to create a nested home page, let's look at an example below. First, an example of the standard homepage is provided.

<% @ Master Language = "C #" AutoEventWireup = "true"
CodeFile = "WebsiteMasterPage. master. cs" Inherits = "WebsiteMasterPage" %>
<Html>
<Head runat = "server" id = "head">
<Title> standard homepage example </title>
</Head>
<Body>
<Form id = "form1" runat = "server">
& Lt; table width = "100%" & gt;
<Tr>
<Td bgcolor = "#006633" colspan = "2">
<Table border = "0" cellpadding = "0" cellspacing = "0" width = "100%">
<Tr>
<Td align = "left">
<A href = "/MasterPage/Default. aspx">

</A>
</Td>
<Td align = "right">

</Td>
</Tr>
</Table>
</Td>
</Tr>
<Tr>
& Lt; td width = "25%" & gt;
<Font color = "# 3300FF"> department 1 <br/> Department 2 <br/> </font>
</Td>
& Lt; td width = "75%" & gt;
<Asp: ContentPlaceHolder ID = "Main" runat = "server">
</Asp: ContentPlaceHolder>
</Td>
</Tr>
<Tr>
<Td colspan = "2"> </td>
</Tr>
<Tr>
<Td bgcolor = "# 0000FF" colspan = "2">
<Font color = "# FFFF00"> note </font>
</Td>
</Tr>
</Table>
</Form>
</Body>
</Html>

The above standard homepage defines the company's Logo, footer, and menu location. It also defines the location of the department's home page to be embedded. This requires the ContentPlaceHolder control ). The Code on the Department Homepage is somewhat different from the code above. The above standard homepage must be referenced in the Code on the Department Homepage. You can add the MasterPageFile attribute to the Department Homepage code. The following is the homepage code of a department:

<% @ Master MasterPageFile = "~ /Templates/WebsiteMasterPage. master "Language =" C #"

AutoEventWireup = "true" CodeFile = "NestedMasterPage. master. cs"

Inherits = "NestedMasterPage" %>
<Asp: Content ID = "Content1" ContentPlaceHolderID = "Main" runat = "server">
& Lt; table width = "100%" & gt;
<Tr>
<Td style = "background-color: BLUE; font-weight: bold; coloar: white">
<Font color = "# FFFF00"> Department homepage </font>
</Td>
</Tr>
<Tr>
<Td>
<Asp: ContentPlaceHolder ID = "NestedMain" runat = "server"/>
</Td>
</Tr>
</Table>
</Asp: Content>

From the code above, we can see that the standard homepage WebsiteMasterPage. master is referenced. A server control is also defined to reference the ContentPlaceHolder's IDID defined in the standard homepage as Main ). Because the Department Homepage is nested in the standard homepage, you must use the Content Server Control. The ContentPlaceHolder control must be added to indicate the position displayed on the Department Homepage.


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.